結果

問題 No.144 エラトステネスのざる
ユーザー Mao-betaMao-beta
提出日時 2024-03-19 00:26:10
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 377 ms / 2,000 ms
コード長 1,572 bytes
コンパイル時間 282 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 88,896 KB
最終ジャッジ日時 2024-03-19 00:26:15
合計ジャッジ時間 4,582 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
78,308 KB
testcase_01 AC 70 ms
78,308 KB
testcase_02 AC 70 ms
78,308 KB
testcase_03 AC 70 ms
78,308 KB
testcase_04 AC 70 ms
78,308 KB
testcase_05 AC 70 ms
78,308 KB
testcase_06 AC 75 ms
80,760 KB
testcase_07 AC 76 ms
80,760 KB
testcase_08 AC 76 ms
80,760 KB
testcase_09 AC 75 ms
80,760 KB
testcase_10 AC 75 ms
80,760 KB
testcase_11 AC 75 ms
80,760 KB
testcase_12 AC 76 ms
80,760 KB
testcase_13 AC 319 ms
88,772 KB
testcase_14 AC 350 ms
88,768 KB
testcase_15 AC 377 ms
88,768 KB
testcase_16 AC 351 ms
88,768 KB
testcase_17 AC 349 ms
88,768 KB
testcase_18 AC 377 ms
88,896 KB
testcase_19 AC 342 ms
88,772 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import math
import bisect
from heapq import heapify, heappop, heappush
from collections import deque, defaultdict, Counter
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
MOD99 = 998244353

input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()
SMI = lambda: input().split()
SLI = lambda: list(SMI())
EI = lambda m: [NLI() for _ in range(m)]


# 高速エラストテネス sieve[n]はnの最小の素因数
def make_prime_table(n):
    sieve = list(range(n + 1))
    sieve[0] = -1
    sieve[1] = -1
    for i in range(4, n + 1, 2):
        sieve[i] = 2
    for i in range(3, int(n ** 0.5) + 1, 2):
        if sieve[i] != i:
            continue
        for j in range(i * i, n + 1, i * 2):
            if sieve[j] == j:
                sieve[j] = i
    return sieve

prime_table = make_prime_table(1000002)
# 素数列挙
primes = [p for i, p in enumerate(prime_table) if i == p]

# 約数の個数 上のprime_tableと組み合わせて使う
def div_num(n):
    result = 1
    while n != 1:
        p = prime_table[n]
        e = 0
        while n % p == 0:
            n //= p
            e += 1
        result *= e+1
    return result


def main():
    N, p = SMI()
    N = int(N)
    p = float(p)
    ans = 0
    for n in range(2, N+1):
        d = div_num(n)
        ans += pow(1-p, d-2)
    print(ans)


if __name__ == "__main__":
    main()
0