結果

問題 No.144 エラトステネスのざる
ユーザー Ryushi-techRyushi-tech
提出日時 2020-06-22 21:49:29
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 648 bytes
コンパイル時間 87 ms
コンパイル使用メモリ 10,924 KB
実行使用メモリ 175,940 KB
最終ジャッジ日時 2023-09-16 19:28:13
合計ジャッジ時間 4,861 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

n, p = map(float, input().split())
n = int(n)

primes = set(range(2, n + 1))
A = set(range(2, n + 1))


def prf(m):
    pf = {}
    for i in range(2, int(m ** 0.5) + 1):
        while not m % i:
            pf[i] = pf.get(i, 0) + 1
            m //= i
    if m > 1:
        pf[m] = 1
    return pf


for i in range(2, int(n ** 0.5 + 1)):
    if i not in primes:
        i += 1
    else:
        ran = range(i * 2, n + 1, i)
        primes.difference_update(ran)
pn = len(list(primes))
B = list(A.difference(primes))

res = pn
for b in B:
    tmp = prf(b)
    e = [max(0, i - 2) for i in tmp.values()]
    res += p ** (len(tmp) + sum(e))
print(res)
0