結果

問題 No.144 エラトステネスのざる
ユーザー poet_nayutapoet_nayuta
提出日時 2018-08-19 18:13:52
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 483 ms / 2,000 ms
コード長 385 bytes
コンパイル時間 325 ms
コンパイル使用メモリ 10,580 KB
実行使用メモリ 49,812 KB
最終ジャッジ日時 2023-08-11 06:13:27
合計ジャッジ時間 8,828 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 131 ms
29,708 KB
testcase_01 AC 131 ms
29,688 KB
testcase_02 AC 133 ms
29,636 KB
testcase_03 AC 134 ms
29,560 KB
testcase_04 AC 128 ms
29,620 KB
testcase_05 AC 128 ms
29,652 KB
testcase_06 AC 129 ms
29,756 KB
testcase_07 AC 131 ms
29,876 KB
testcase_08 AC 127 ms
29,744 KB
testcase_09 AC 128 ms
29,856 KB
testcase_10 AC 130 ms
29,736 KB
testcase_11 AC 129 ms
29,808 KB
testcase_12 AC 130 ms
29,760 KB
testcase_13 AC 483 ms
49,728 KB
testcase_14 AC 407 ms
49,688 KB
testcase_15 AC 401 ms
49,724 KB
testcase_16 AC 416 ms
49,812 KB
testcase_17 AC 407 ms
49,620 KB
testcase_18 AC 413 ms
49,572 KB
testcase_19 AC 398 ms
49,800 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np

def solve(N, p):
    ps = np.ones(N+1)
    c = int(np.sqrt(N))+1
    for i in range(2, c):
        ind = np.arange(0, (N+1), i)
        ps[ind[2:]] *= (1 - p)
        _ind = ind[ind >= c * i]
        _ind = _ind[(_ind % i == 0) * (_ind != i**2)]
        ps[_ind] *= (1 - p)
    return ps[2:].sum()

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

print(solve(N, p))
0