結果
| 問題 |
No.2249 GCDistance
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-05-19 00:54:32 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 2,495 ms / 5,000 ms |
| コード長 | 516 bytes |
| コンパイル時間 | 602 ms |
| コンパイル使用メモリ | 82,324 KB |
| 実行使用メモリ | 389,560 KB |
| 最終ジャッジ日時 | 2024-09-27 11:05:13 |
| 合計ジャッジ時間 | 31,053 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 10 |
ソースコード
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)