結果

問題 No.144 エラトステネスのざる
ユーザー FromBooskaFromBooska
提出日時 2023-02-15 13:35:29
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 219 ms / 2,000 ms
コード長 1,124 bytes
コンパイル時間 935 ms
コンパイル使用メモリ 87,124 KB
実行使用メモリ 85,792 KB
最終ジャッジ日時 2023-09-24 22:55:06
合計ジャッジ時間 4,368 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
71,412 KB
testcase_01 AC 66 ms
71,584 KB
testcase_02 AC 67 ms
71,460 KB
testcase_03 AC 73 ms
71,252 KB
testcase_04 AC 67 ms
71,320 KB
testcase_05 AC 67 ms
71,376 KB
testcase_06 AC 72 ms
76,332 KB
testcase_07 AC 74 ms
76,720 KB
testcase_08 AC 74 ms
76,532 KB
testcase_09 AC 76 ms
76,756 KB
testcase_10 AC 73 ms
76,728 KB
testcase_11 AC 74 ms
76,748 KB
testcase_12 AC 74 ms
76,416 KB
testcase_13 AC 163 ms
84,972 KB
testcase_14 AC 211 ms
85,312 KB
testcase_15 AC 217 ms
85,792 KB
testcase_16 AC 219 ms
85,632 KB
testcase_17 AC 215 ms
85,320 KB
testcase_18 AC 215 ms
85,664 KB
testcase_19 AC 188 ms
85,264 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# 落とし穴がある。たとえば8
# 2でも4でも倍数としてひっかからなければ8は生き残る
# 2で8がひっかからない確率は1-exe_prob
# 4で8がひっかからないかどうかを考えるときに4が生きているか死んでいるかの場合分けをしたくなる
# しかし4が死んでいれば8も死んでいる、つまり完全相関
# つまり4まで来たときに8が生き残っていれば4も生き残っている
# 8が生き残るかは2と4の2回のテストをクリアすればいい、4の場合分けは必要ない
# つまり各数の約数の個数だけが必要となる
# (1-exe_prob)**約数個数は時間かかるのでpow
# さらに約数個数は下から積み上げる、エラトステネスの容量、そうしないとTLE

N, exe_prob = map(float, input().split())
N = int(N)

div_count = [0]*(N+1)

for p in range(2, N+1):
    for q in range(p*2, N+1, p):
        div_count[q] += 1

ans = 0
for i in range(2, N+1):
    if div_count[i] == 0:
        ans += 1
    else:
        ans += pow(1-exe_prob, div_count[i])

print(ans)

#print(div_count)
0