QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#76854 | #5503. Euclidean Algorithm | LYC_music | ML | 0ms | 0kb | C++14 | 1.2kb | 2023-02-12 13:32:45 | 2023-02-12 13:32:48 |
Judging History
answer
#include <bits/stdc++.h>
#define poly vector<int>
#define IOS ios::sync_with_stdio(false)
#define ll long long
#define mp make_pair
#define mt make_tuple
#define pa pair<int, int>
#define fi first
#define se second
#define inf 1e18
#define mod 998244353
// #define int ll
#define N 1005
using namespace std;
const int B=2000000;
ll n, ans;
int g[B+5];
inline ll query(ll X)
{
if (X <= B)
return g[X];
ll Y = 0;
for (ll L = 1; L < X; L++)
{
ll R = X / (X / L);
Y += (R - L + 1) * ((X / L) - 1);
L = R;
}
return Y;
}
void BellaKira()
{
cin >> n;
ans = 0;
for (ll l = 1; l < n; l++)
{
ll r = n / (n / l);
r = min(r, n - 1);
ll X = ((n / l) - 1);
ll Y = query(X);
ans += Y * (r - l + 1);
l = r;
}
ans+=query(n);
cout << ans << '\n';
}
signed main()
{
IOS;
cin.tie(0);
ll T = 1;
cin >> T;
for (ll X = 1; X <= B; ++X)
{
for (ll Y=X+X;Y<=B;Y+=X)
g[Y]+=1;
g[X]+=g[X-1];
}
// cout<<g[B]<<'\n';
// return 0;
while (T--)
{
BellaKira();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Memory Limit Exceeded
input:
3 2 5 14