結果

問題 No.144 エラトステネスのざる
ユーザー matsu7874matsu7874
提出日時 2015-12-05 01:22:25
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 956 bytes
コンパイル時間 665 ms
コンパイル使用メモリ 10,768 KB
実行使用メモリ 7,972 KB
最終ジャッジ日時 2023-10-12 15:26:35
合計ジャッジ時間 5,016 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,844 KB
testcase_01 AC 15 ms
7,844 KB
testcase_02 AC 15 ms
7,776 KB
testcase_03 AC 16 ms
7,860 KB
testcase_04 AC 15 ms
7,800 KB
testcase_05 AC 15 ms
7,844 KB
testcase_06 AC 18 ms
7,808 KB
testcase_07 AC 18 ms
7,940 KB
testcase_08 AC 18 ms
7,864 KB
testcase_09 AC 18 ms
7,800 KB
testcase_10 AC 18 ms
7,836 KB
testcase_11 AC 18 ms
7,884 KB
testcase_12 AC 17 ms
7,972 KB
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

def prime_sieve(n):
    # 素数リスト(エラトステネスの篩)
    # N以下の素数のリストを返す
    is_prime = [True for i in range(n + 1)]
    is_prime[0] = False
    is_prime[1] = False
    for i in range(4, n + 1, 2):
        is_prime[i] = False
    for i in range(3, int(n**0.5 + 1), 2):
        if is_prime[i]:
            for j in range(i * i, n + 1, i):
                is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]

def get_divisors(n):
    # 約数列挙
    # リストがソートされていないことに注意せよ。
    divisors = set()
    for i in range(1, int(n**0.5) + 1):
        if n % i == 0:
            divisors.add(i)
            divisors.add(n // i)
    return list(divisors)

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

e = 0
for i in range(2,N+1):
    dvs = len(get_divisors(i))
    # print(i,dvs)
    if dvs == 2:
        e += 1
    else:
        e += (1-p)**(dvs-2)
print(e)
0