結果

問題 No.2249 GCDistance
ユーザー titiatitia
提出日時 2023-03-17 22:40:26
言語 PyPy3
(7.3.15)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,187 bytes
コンパイル時間 182 ms
コンパイル使用メモリ 81,672 KB
実行使用メモリ 233,084 KB
最終ジャッジ日時 2023-10-18 15:39:44
合計ジャッジ時間 64,340 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

import sys
input = sys.stdin.readline

# エラトステネスの篩を用いた素因数分解・約数列挙
MAX=10**7+10 # 使いたい最大値を指定

# Sieve[i]で、iの最も小さい約数を返す。
Sieve=[i for i in range(MAX)]

for i in range(2,MAX):
    if Sieve[i]!=i:
        continue
    
    for j in range(i,MAX,i):
        if Sieve[j]==j:
            Sieve[j]=i

# 素因数分解
def fact(x):
    D=dict()
    while x!=1:
        k=Sieve[x]
        if k in D:
            D[k]+=1
        else:
            D[k]=1
        x//=k
    return D

# 約数列挙
def faclist(x):
    LIST=[1]
    while x!=1:
        k=Sieve[x]
        count=0
        while x%k==0:
            count+=1
            x//=k

        LIST2=[]
        for l in LIST:
            for i in range(1,count+1):
                LIST2.append(l*k**i)
        LIST+=LIST2

    return LIST

def euler_totient(x):
    FACT=fact(x)
    ANS=x
    for f in FACT:
        ANS=ANS*(f-1)//f

    return ANS

ANS=[0]*(10**7+10)

for i in range(2,10**7+1):
    k=euler_totient(i)
    ANS[i]=ANS[i-1]+i-1+(i-1-k)

#print(ANS[:10])

T=int(input())
for tests in range(T):
    N=int(input())
    print(ANS[N])

    
0