結果

問題 No.2249 GCDistance
ユーザー ShirotsumeShirotsume
提出日時 2023-03-17 22:18:52
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,504 ms / 5,000 ms
コード長 728 bytes
コンパイル時間 174 ms
コンパイル使用メモリ 81,816 KB
実行使用メモリ 154,248 KB
最終ジャッジ日時 2023-10-18 15:13:56
合計ジャッジ時間 19,678 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,391 ms
153,608 KB
testcase_01 AC 1,485 ms
154,248 KB
testcase_02 AC 1,504 ms
154,244 KB
testcase_03 AC 1,495 ms
154,248 KB
testcase_04 AC 1,430 ms
154,144 KB
testcase_05 AC 1,496 ms
154,244 KB
testcase_06 AC 1,498 ms
154,240 KB
testcase_07 AC 1,494 ms
154,244 KB
testcase_08 AC 1,409 ms
154,056 KB
testcase_09 AC 1,490 ms
154,248 KB
testcase_10 AC 1,502 ms
154,228 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda: sys.stdin.readline().rstrip()
ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(mi())
INF = 2**63-1
mod = 998244353


# calculate φ(x) for 1 <= x <= M
M = 10**7 + 1
phi = list(range(M+1))
for x in range(2, M+1):
    if phi[x] == x:
        for y in range(x, M+1, x):
            phi[y] = phi[y] // x * (x-1)
for x in range(2, M+1):
    phi[x] += phi[x - 1] 

def solve():
    #i, jについて,互いに素なら答えは1
    #互いに素でないなら,1では行けない.i → 1 → jと行くと,2が達成できる
    #よって,答えは n * (n - 1) - Σφ(x)
    n = ii()

    print(n * (n - 1) - phi[n] + 1)
    
for _ in range(ii()):
    solve()
0