QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#76855 | #5503. Euclidean Algorithm | LYC_music | TL | 13995ms | 7292kb | C++14 | 1.2kb | 2023-02-12 13:32:58 | 2023-02-12 13:32:59 |
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;
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();
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 22ms
memory: 7292kb
input:
3 2 5 14
output:
1 9 62
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 13995ms
memory: 7180kb
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