結果

問題 No.144 エラトステネスのざる
ユーザー vwxyzvwxyz
提出日時 2023-04-03 07:50:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 236 ms / 2,000 ms
コード長 518 bytes
コンパイル時間 176 ms
コンパイル使用メモリ 81,308 KB
実行使用メモリ 98,948 KB
最終ジャッジ日時 2023-10-25 05:18:24
合計ジャッジ時間 3,142 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,384 KB
testcase_01 AC 37 ms
53,264 KB
testcase_02 AC 37 ms
53,464 KB
testcase_03 AC 37 ms
53,264 KB
testcase_04 AC 37 ms
53,264 KB
testcase_05 AC 37 ms
53,264 KB
testcase_06 AC 41 ms
59,196 KB
testcase_07 AC 42 ms
59,392 KB
testcase_08 AC 42 ms
59,392 KB
testcase_09 AC 43 ms
59,392 KB
testcase_10 AC 42 ms
59,392 KB
testcase_11 AC 42 ms
59,392 KB
testcase_12 AC 42 ms
59,316 KB
testcase_13 AC 225 ms
98,428 KB
testcase_14 AC 236 ms
98,628 KB
testcase_15 AC 236 ms
98,628 KB
testcase_16 AC 222 ms
98,628 KB
testcase_17 AC 230 ms
98,628 KB
testcase_18 AC 230 ms
98,948 KB
testcase_19 AC 222 ms
98,560 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline=sys.stdin.readline

def Divisor_Counts(N):
    divisor_counts=[float('inf')]+[1]*N
    for p in range(2,N+1):
        if divisor_counts[p]!=1:
            continue
        pp=p
        e=1
        while pp<=N:
            for i in range(pp,N+1,pp):
                divisor_counts[i]+=divisor_counts[i]//e
            e+=1
            pp*=p
    return divisor_counts

N,p=readline().split()
N=int(N)
p=float(p)
ans=0
cnt=Divisor_Counts(N)
for n in range(2,N+1):
    ans+=(1-p)**(cnt[n]-2)
print(ans)
0