結果

問題 No.1514 Squared Matching
ユーザー 👑 KazunKazun
提出日時 2021-05-22 04:33:14
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 1,108 bytes
コンパイル時間 400 ms
コンパイル使用メモリ 81,960 KB
実行使用メモリ 843,160 KB
最終ジャッジ日時 2024-04-18 17:21:22
合計ジャッジ時間 37,467 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
52,096 KB
testcase_01 MLE -
testcase_02 AC 41 ms
51,712 KB
testcase_03 AC 39 ms
52,096 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 MLE -
testcase_09 MLE -
testcase_10 MLE -
testcase_11 MLE -
testcase_12 MLE -
testcase_13 MLE -
testcase_14 MLE -
testcase_15 MLE -
testcase_16 MLE -
testcase_17 MLE -
testcase_18 MLE -
testcase_19 MLE -
testcase_20 MLE -
testcase_21 MLE -
testcase_22 WA -
testcase_23 WA -
testcase_24 MLE -
testcase_25 MLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#エラトステネスの篩
def Sieve_of_Eratosthenes(N,mode=False):
    """Nまでのエラトステネスの篩を実行

    N:自然数
    mode:False->素数のリスト,True->素数かどうかのリスト
    (False->[2,3,5,...],True->[0,0,1,1,0,1,...])
    """

    if N==0:
        return [0]

    T=[1]*(N+1)
    T[0]=T[1]=0

    for x in range(4,N+1,2): T[x]=0
    for x in range(9,N+1,3): T[x]=0

    a=5
    Flag=0
    while a*a<=N:
        if T[a]:
            b=a*a
            c=2*a
            while b<=N:
                T[b]=0
                b+=c
        a+=2+2*Flag
        Flag^=1

    if mode:
        return T
    else:
        return [k for k in range(N+1) if T[k]]
#==================================================
N=int(input())
M=0
while (M+1)*(M+1)<=N:
    M+=1

Y=[0]*(N+1); Y[1]=1
A=list(range(N+1))

for p in Sieve_of_Eratosthenes(M):
    if p*p>N: break

    q=s=p*p
    Y[q]=1
    while q<=N:
        r=q
        while r<=N:
            A[r]//=s
            r+=q
        q*=p*p

for i in range(1,N+1): Y[i]+=Y[i-1]

K=0
for i in range(1,N+1):
    K+=Y[N//A[i]]

print(K)
0