結果

問題 No.144 エラトステネスのざる
ユーザー vwxyzvwxyz
提出日時 2023-04-03 07:49:57
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 837 ms / 2,000 ms
コード長 518 bytes
コンパイル時間 107 ms
コンパイル使用メモリ 11,816 KB
実行使用メモリ 25,520 KB
最終ジャッジ日時 2023-10-25 05:18:19
合計ジャッジ時間 7,725 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
10,024 KB
testcase_01 AC 31 ms
9,992 KB
testcase_02 AC 29 ms
10,024 KB
testcase_03 AC 29 ms
9,992 KB
testcase_04 AC 28 ms
9,992 KB
testcase_05 AC 28 ms
9,992 KB
testcase_06 AC 29 ms
10,000 KB
testcase_07 AC 29 ms
10,032 KB
testcase_08 AC 29 ms
10,032 KB
testcase_09 AC 29 ms
10,032 KB
testcase_10 AC 29 ms
10,032 KB
testcase_11 AC 29 ms
10,032 KB
testcase_12 AC 30 ms
10,032 KB
testcase_13 AC 778 ms
25,520 KB
testcase_14 AC 797 ms
25,520 KB
testcase_15 AC 818 ms
25,520 KB
testcase_16 AC 811 ms
25,520 KB
testcase_17 AC 802 ms
25,520 KB
testcase_18 AC 837 ms
25,520 KB
testcase_19 AC 799 ms
25,520 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