QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#77774 | #5503. Euclidean Algorithm | XKError | TL | 29939ms | 7528kb | C++ | 837b | 2023-02-15 16:25:26 | 2023-02-15 16:25:29 |
Judging History
answer
#include <bits/stdc++.h>
#define maxn 1000005
#define ll long long
using namespace std;
ll n;
int d[maxn];
ll ds(ll x) {
if (x < maxn) return d[x];
ll res = 0;
for (ll l = 1, r; l <= x; l = r + 1) {
r = x / (x / l);
res += x / l * (r - l + 1);
}
return res;
}
int main() {
// cout<<(sizeof d) / 1024 / 1024<<endl;
int T;
scanf("%d", &T);
for (int i = 1; i < maxn; i++) {
for (int j = i; j < maxn; j += i) {
++d[j];
}
d[i] += d[i - 1];
}
while (T--) {
scanf("%lld", &n);
ll res = 0, lst = 0;
// int T = 0;
for (ll l = 1, r; l <= n; l = r + 1) {
// ++T;
r = n / (n / l);
// if (T % 1000 == 0) cout<<T<<":"<<l<<" "<<r<<" "<<r - l<<endl;
ll now = ds(r - 1);
res += (now - lst) * (n / l);
lst = now;
}
printf("%lld\n", res);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 26ms
memory: 7424kb
input:
3 2 5 14
output:
1 9 62
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 14036ms
memory: 7472kb
input:
3 29107867360 65171672278 41641960535
output:
8921593237533 21300450379732 13136180138425
result:
ok 3 lines
Test #3:
score: 0
Accepted
time: 29939ms
memory: 7528kb
input:
3 90076809172 100000000000 99913139559
output:
30192292781431 33790187414013 33758574429172
result:
ok 3 lines
Test #4:
score: -100
Time Limit Exceeded
input:
3 99997992652 99832769119 99997176887