QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#77061 | #5503. Euclidean Algorithm | Golovanov399 | TL | 20931ms | 3412kb | C++20 | 676b | 2023-02-13 00:59:11 | 2023-02-13 00:59:14 |
Judging History
answer
#include <iostream>
using namespace std;
int nxt() {
int x;
cin >> x;
return x;
}
long long f(long long n) {
n -= 1;
long long ans = 0;
long long s = 0;
for (long long d = 1; d * d <= n; d = n / (n / d) + 1) {
s = d;
long long k = n / d;
ans += (n / k - d + 1) * k;
}
return 2 * ans - s * s;
}
void solve() {
long long n;
cin >> n;
long long ans = 0;
for (long long d = 1; d <= n; d = n / (n / d) + 1) {
long long k = n / d;
ans += (n / k - d + 1) * f(k);
}
cout << ans << "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t = nxt();
while (t--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3336kb
input:
3 2 5 14
output:
1 9 62
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 20931ms
memory: 3412kb
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