結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
12,384 KB
testcase_01 AC 17 ms
7,940 KB
testcase_02 WA -
testcase_03 AC 17 ms
7,980 KB
testcase_04 AC 17 ms
8,012 KB
testcase_05 AC 17 ms
7,972 KB
testcase_06 AC 30 ms
8,124 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 30 ms
8,056 KB
testcase_12 AC 31 ms
8,124 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
memo = {}
for i in range(2, N+1):
    if i in primes:
        count += 1.0
        memo[i] = 1
    else:
        cnt = 0
        for j in range(2,i):
            if i % j == 0:
                cnt += 1
                if memo.get(i//j,0) != 0:
                    cnt += memo[i//j]
                    break
        memo[i] = cnt
        count += (1.0-p) ** cnt
print(count)
0