QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#77780 | #5503. Euclidean Algorithm | XKError | ML | 0ms | 0kb | C++ | 856b | 2023-02-15 16:31:26 | 2023-02-15 16:31:27 |
Judging History
answer
#include <bits/stdc++.h>
#define maxn 1200005
#define ll long long
using namespace std;
int i, j, T;
ll n;
int d[maxn];
ll res, l, r;
ll ds(ll x) {
if (x < maxn) return d[x];
res = 0;
for (l = 1; 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;
scanf("%d", &T);
for (i = 1; i < maxn; i++) {
for (j = i; j < maxn; j += i) {
++d[j];
}
d[i] += d[i - 1];
}
ll res, lst, l, r, now;
while (T--) {
scanf("%lld", &n);
res = 0, lst = 0;
// int T = 0;
for (l = 1; l <= n; l = r + 1) {
// ++T;
r = n / (n / l);
// if (T % 1000 == 0) cout<<T<<":"<<l<<" "<<r<<" "<<r - l<<endl;
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: 0
Memory Limit Exceeded
input:
3 2 5 14
output:
1 9 62