QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#76851 | #5503. Euclidean Algorithm | LYC_music | ML | 0ms | 0kb | C++14 | 1.4kb | 2023-02-12 13:30:17 | 2023-02-12 13:30:20 |
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=900000;
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: 0
Memory Limit Exceeded
input:
3 2 5 14