結果

問題 No.2249 GCDistance
ユーザー convexineqconvexineq
提出日時 2023-06-29 15:58:03
言語 PyPy3
(7.3.15)
結果
OLE  
実行時間 -
コード長 771 bytes
コンパイル時間 439 ms
コンパイル使用メモリ 86,872 KB
最終ジャッジ日時 2023-09-20 11:17:53
合計ジャッジ時間 22,319 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 OLE -
testcase_01 OLE -
testcase_02 OLE -
testcase_03 OLE -
testcase_04 OLE -
testcase_05 OLE -
testcase_06 OLE -
testcase_07 OLE -
testcase_08 OLE -
testcase_09 OLE -
testcase_10 OLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline = sys.stdin.readline
 
#n = int(readline())
#*a, = map(int,readline().split())
# b = [list(map(int,readline().split())) for _ in range()]

def enumerate_tortient(N):
    primes = []
    lpf = [0]*(N+1) # least prime factor
    tor = [1]*(N+1); tor[0] = 0
    for x in range(2,N+1):
        if lpf[x] == 0:
            lpf[x] = x
            primes.append(x)
            tor[x] = x-1
        for p in primes:
            if p > lpf[x] or x*p > N: break
            lpf[x*p] = p
            tor[x*p] = tor[x]*(p if lpf[x] == p else p-1)
    return tor

T = int(readline())

N = 10**7
tor = enumerate_tortient(N)
print(tor)
tor[1] -= 1
for i in range(1,N+1):
    tor[i] += tor[i-1]

for _ in range(T):
    n = int(readline())
    print(n*(n-1) - tor[n])
0