結果

問題 No.2249 GCDistance
ユーザー 👑 chro_96chro_96
提出日時 2023-03-17 22:44:36
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 931 ms / 5,000 ms
コード長 799 bytes
コンパイル時間 420 ms
コンパイル使用メモリ 30,440 KB
実行使用メモリ 119,152 KB
最終ジャッジ日時 2023-10-18 15:45:16
合計ジャッジ時間 13,200 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 848 ms
119,152 KB
testcase_01 AC 930 ms
119,152 KB
testcase_02 AC 919 ms
119,152 KB
testcase_03 AC 921 ms
119,152 KB
testcase_04 AC 884 ms
119,152 KB
testcase_05 AC 920 ms
119,152 KB
testcase_06 AC 928 ms
119,152 KB
testcase_07 AC 931 ms
119,152 KB
testcase_08 AC 857 ms
119,152 KB
testcase_09 AC 921 ms
119,152 KB
testcase_10 AC 917 ms
119,152 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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