結果

問題 No.144 エラトステネスのざる
ユーザー nbisconbisco
提出日時 2017-01-28 18:33:25
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 525 bytes
コンパイル時間 207 ms
コンパイル使用メモリ 10,804 KB
実行使用メモリ 38,908 KB
最終ジャッジ日時 2023-08-25 13:21:27
合計ジャッジ時間 4,716 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
12,340 KB
testcase_01 AC 16 ms
7,928 KB
testcase_02 AC 16 ms
7,912 KB
testcase_03 AC 16 ms
7,916 KB
testcase_04 AC 17 ms
7,928 KB
testcase_05 AC 16 ms
7,920 KB
testcase_06 AC 70 ms
7,956 KB
testcase_07 AC 70 ms
8,012 KB
testcase_08 AC 70 ms
7,988 KB
testcase_09 AC 71 ms
7,912 KB
testcase_10 AC 70 ms
7,984 KB
testcase_11 AC 70 ms
7,860 KB
testcase_12 AC 73 ms
7,920 KB
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import math

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

cand = [i for i in range(3, N+1, 2)]
primes = [2]
while len(cand) > 0:
    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