QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#76850 | #5503. Euclidean Algorithm | LYC_music | ML | 0ms | 0kb | C++14 | 1.4kb | 2023-02-12 13:29:06 | 2023-02-12 13:29:37 |
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=1000000;
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();
}
}
详细
Test #1:
score: 0
Memory Limit Exceeded
input:
3 2 5 14