結果

問題 No.2249 GCDistance
コンテスト
ユーザー chro_96
提出日時 2023-03-17 22:44:36
言語 C(gnu17)
(gcc 15.2.0)
コンパイル:
gcc-15 -O2 -std=gnu17 -Wno-error=implicit-function-declaration -Wno-error=implicit-int -Wno-error=incompatible-pointer-types -Wno-error=int-conversion -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
AC  
実行時間 1,025 ms / 5,000 ms
コード長 799 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 201 ms
コンパイル使用メモリ 37,760 KB
最終ジャッジ日時 2026-02-22 10:19:52
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 10
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <stdio.h>

int main () {
  int t = 0;
  int n = 0;
  
  int res = 0;
  
  long long sum[10000001] = {};
  int rem[10000001] = {};
  
  for (int i = 2; i <= 10000000; i++) {
    sum[i] = 1LL;
    rem[i] = i;
  }
  
  for (int i = 2; i <= 10000000; i++) {
    if (rem[i] > 1) {
      sum[i] = (long long)(i-1);
      for (int j = 2; i*j <= 10000000; j++) {
        sum[i*j] *= (long long)(i-1);
        rem[i*j] /= i;
        while (rem[i*j]%i == 0) {
          sum[i*j] *= (long long)i;
          rem[i*j] /= i;
        }
      }
    }
    sum[i] += sum[i-1];
  }
  
  res = scanf("%d", &t);
  while (t > 0) {
    long long ans = 0LL;
    res = scanf("%d", &n);
    ans = (long long)n;
    ans *= (long long)(n-1);
    ans -= sum[n];
    printf("%lld\n", ans);
    t--;
  }
  
  return 0;
}
0