結果

問題 No.2249 GCDistance
ユーザー qibqib
提出日時 2023-05-19 00:54:32
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,674 ms / 5,000 ms
コード長 516 bytes
コンパイル時間 447 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 388,860 KB
最終ジャッジ日時 2023-12-21 20:19:03
合計ジャッジ時間 31,682 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2,021 ms
388,084 KB
testcase_01 AC 2,601 ms
388,736 KB
testcase_02 AC 2,674 ms
388,732 KB
testcase_03 AC 2,509 ms
388,732 KB
testcase_04 AC 2,235 ms
388,732 KB
testcase_05 AC 2,510 ms
388,732 KB
testcase_06 AC 2,506 ms
388,736 KB
testcase_07 AC 2,489 ms
388,860 KB
testcase_08 AC 2,049 ms
388,608 KB
testcase_09 AC 2,513 ms
388,736 KB
testcase_10 AC 2,459 ms
388,732 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

t = int(input())

m = 10 ** 7
totient = [i for i in range(m + 1)]
prime = [None for _ in range(m + 1)]

for x in range(2, m + 1):
  if not prime[x] is None:
    continue

  prime[x] = True
  totient[x] *= (x - 1)
  totient[x] //= x
  for y in range(2 * x, m + 1, x):
    totient[y] *= (x - 1)
    totient[y] //= x
    prime[y] = False

dp = [0 for _ in range(m + 2)]
for x in range(1, m + 1):
  dp[x] = dp[x - 1] + totient[x]

for _ in range(t):
  n = int(input())
  print(dp[n] + (n * (n - 1) // 2 - dp[n]) * 2 + 1)
0