結果

問題 No.144 エラトステネスのざる
ユーザー matsu7874matsu7874
提出日時 2015-12-20 10:10:30
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 972 bytes
コンパイル時間 181 ms
コンパイル使用メモリ 81,652 KB
実行使用メモリ 92,332 KB
最終ジャッジ日時 2023-10-17 14:06:44
合計ジャッジ時間 4,887 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,676 KB
testcase_01 AC 38 ms
53,552 KB
testcase_02 AC 36 ms
53,556 KB
testcase_03 AC 36 ms
53,548 KB
testcase_04 AC 37 ms
53,548 KB
testcase_05 AC 36 ms
53,548 KB
testcase_06 AC 46 ms
61,836 KB
testcase_07 AC 46 ms
61,836 KB
testcase_08 AC 48 ms
61,836 KB
testcase_09 AC 46 ms
61,836 KB
testcase_10 AC 46 ms
61,836 KB
testcase_11 AC 46 ms
61,836 KB
testcase_12 AC 46 ms
61,836 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)
primes = prime_sieve(N)
primes.sort()
e = 0
for i in range(2, N + 1):
    if i in primes:
        e += 1
    else:
        e += (1 - p)**(len(get_divisors(i)) - 2)
print(e)
0