結果

問題 No.2249 GCDistance
ユーザー convexineqconvexineq
提出日時 2023-06-29 16:00:27
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 751 ms / 5,000 ms
コード長 772 bytes
コンパイル時間 587 ms
コンパイル使用メモリ 87,316 KB
実行使用メモリ 262,404 KB
最終ジャッジ日時 2023-09-20 11:18:04
合計ジャッジ時間 10,969 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 644 ms
262,204 KB
testcase_01 AC 750 ms
262,404 KB
testcase_02 AC 751 ms
262,252 KB
testcase_03 AC 743 ms
261,900 KB
testcase_04 AC 685 ms
262,032 KB
testcase_05 AC 745 ms
261,996 KB
testcase_06 AC 741 ms
262,192 KB
testcase_07 AC 740 ms
262,188 KB
testcase_08 AC 649 ms
261,940 KB
testcase_09 AC 742 ms
262,340 KB
testcase_10 AC 726 ms
262,128 KB
権限があれば一括ダウンロードができます

ソースコード

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