結果

問題 No.144 エラトステネスのざる
ユーザー nbisconbisco
提出日時 2017-01-28 17:43:58
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 504 bytes
コンパイル時間 701 ms
コンパイル使用メモリ 10,808 KB
実行使用メモリ 38,792 KB
最終ジャッジ日時 2023-08-25 13:18:52
合計ジャッジ時間 5,577 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
12,192 KB
testcase_01 AC 16 ms
7,816 KB
testcase_02 AC 16 ms
7,840 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 AC 69 ms
7,828 KB
testcase_07 AC 69 ms
7,876 KB
testcase_08 AC 70 ms
7,836 KB
testcase_09 AC 73 ms
7,816 KB
testcase_10 AC 69 ms
7,756 KB
testcase_11 AC 73 ms
7,824 KB
testcase_12 AC 72 ms
7,948 KB
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

tmp = input().split(" ")
N = int(tmp[0])
p = float(tmp[1])

cand = [i for i in range(3, N+1, 2)]
primes = [2]
while True:
    primes.append(cand[0])
    if primes[-1] * primes[-1] > N:
        break
    cand = [i for i in cand[1:] if i % primes[-1] != 0]
primes = set(primes)
count = 0
for i in range(2, N+1):
    if i in primes:
        count += 1.0
    else:
        cnt = 0
        for j in range(2, i):
            if i % j == 0:
                cnt += 1
        count += (1.0-p) ** cnt

print(count)
0