Time Exceeded
Code
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
cin.tie(0) -> sync_with_stdio(0);
const int N = 1e6 + 6;
int64_t a[N] {};
for (int i = 1; i < N; i++) {
for (int j = i * 2; j < N; j += i) {
a[j] += 1;
}
a[i] += a[i - 1];
}
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
if (n < N) {
cout << a[n] << "\n";
continue;
}
int x = n, d = 1;
int64_t ans = 0;
while (d <= n) {
int nxt = n / (n / d);
ans += (n / d) * 1LL * (nxt - d + 1);
d = nxt + 1;
}
cout << ans - n << "\n";
}
return 0;
}
Information
- Submit By
- Type
- Submission
- Problem
- P1207 D2. GCD equal Absolute Value (Hard Version)
- Contest
- Educational Round 1
- Language
- C++17 (G++ 13.2.0)
- Submit At
- 2025-07-14 17:57:37
- Judged At
- 2025-07-14 17:57:37
- Judged By
- Score
- 5
- Total Time
- ≥1100ms
- Peak Memory
- ≥8.199 MiB