QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#76852 | #5503. Euclidean Algorithm | LYC_music | TL | 20058ms | 7232kb | C++14 | 1.4kb | 2023-02-12 13:30:34 | 2023-02-12 13:30:35 |
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=500000;
int n, ans, g[B+5];
int query(int X)
{
if (X <= B)
return g[X];
int t = n / X;
int Y = 0;
for (int L = 1; L < X; L++)
{
int R = X / (X / L);
Y += (R - L + 1) * ((X / L) - 1);
L = R;
}
return Y;
}
void BellaKira()
{
cin >> n;
ans = 0;
for (int l = 1; l < n; l++)
{
int r = n / (n / l);
r = min(r, n - 1);
int X = ((n / l) - 1);
int Y = query(X);
ans += Y * (r - l + 1);
l = r;
}
ans+=query(n);
// for (int l = 1; l < n; l++)
// {
// int r = n / (n / l);
// r = min(r, n - 1);
// ans += (r - l + 1) * ((n / l) - 1);
// l = r;
// }
cout << ans << '\n';
}
signed main()
{
IOS;
cin.tie(0);
int T = 3;
cin >> T;
for (int X = 1; X <= B; ++X)
{
for (int Y=X+X;Y<=B;Y+=X)
g[Y]+=1;
g[X]+=g[X-1];
// cout<<X<<" "<<g[X]<<'\n';
}
while (T--)
{
BellaKira();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 16ms
memory: 7232kb
input:
3 2 5 14
output:
1 9 62
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 20058ms
memory: 7184kb
input:
3 29107867360 65171672278 41641960535
output:
8921593237533 21300450379732 13136180138425
result:
ok 3 lines
Test #3:
score: -100
Time Limit Exceeded
input:
3 90076809172 100000000000 99913139559