結果

問題 No.144 エラトステネスのざる
ユーザー FromBooskaFromBooska
提出日時 2023-02-25 21:15:44
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 417 ms / 2,000 ms
コード長 589 bytes
コンパイル時間 417 ms
コンパイル使用メモリ 86,520 KB
実行使用メモリ 93,276 KB
最終ジャッジ日時 2023-10-11 17:20:52
合計ジャッジ時間 5,327 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,236 KB
testcase_01 AC 74 ms
71,172 KB
testcase_02 AC 79 ms
71,228 KB
testcase_03 AC 76 ms
71,164 KB
testcase_04 AC 76 ms
71,128 KB
testcase_05 AC 76 ms
71,208 KB
testcase_06 AC 83 ms
76,028 KB
testcase_07 AC 82 ms
76,556 KB
testcase_08 AC 82 ms
76,404 KB
testcase_09 AC 82 ms
76,332 KB
testcase_10 AC 81 ms
76,448 KB
testcase_11 AC 82 ms
76,304 KB
testcase_12 AC 82 ms
76,152 KB
testcase_13 AC 370 ms
92,468 KB
testcase_14 AC 386 ms
92,852 KB
testcase_15 AC 391 ms
92,932 KB
testcase_16 AC 384 ms
93,012 KB
testcase_17 AC 417 ms
93,268 KB
testcase_18 AC 397 ms
93,276 KB
testcase_19 AC 370 ms
92,744 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# 確率が独立でなく従属なケース
# たとえば8
# 2のときに倍数を除くのを忘れていれば、4も8も生きている
# 4が生きている場合、死んでいる場合の場合分けは必要ない

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

is_prime = [1]*(N+1)
is_prime[0] = 0  
is_prime[1] = 0
div_count = [0]*(N+1)

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

EV = 0
for i in range(2, N+1):
    if is_prime[i] == 1:
        EV += 1
    else:
        EV += (1-p)**div_count[i]
print(EV)


0