QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#77778 | #5503. Euclidean Algorithm | XKError | ML | 0ms | 0kb | C++ | 837b | 2023-02-15 16:29:19 | 2023-02-15 16:29:23 |
Judging History
answer
#include <bits/stdc++.h>
#define maxn 1200005
#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;
}
詳細信息
Test #1:
score: 0
Memory Limit Exceeded
input:
3 2 5 14
output:
1 9 62