/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 67ms 8.188 MiB
#2 Accepted 86ms 7.977 MiB
#3 Time Exceeded ≥1100ms ≥8.199 MiB
#4 Time Exceeded ≥1100ms ≥8.184 MiB

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