結果

問題 No.106 素数が嫌い!2
ユーザー nbisconbisco
提出日時 2017-01-19 00:36:24
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 726 bytes
コンパイル時間 127 ms
コンパイル使用メモリ 10,956 KB
実行使用メモリ 141,632 KB
最終ジャッジ日時 2023-08-24 17:11:09
合計ジャッジ時間 12,804 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

import math

def count_primes(i, K):
    global primes
    global memo
    count = 0
    for j in primes:
        if i < j:
            break
        if i % j == 0:
            count += 1
            if count >= K:
                break
        while i % j == 0:
            i //= j
            if memo.get(i, False):
                return True
    return count >= K

n = int(math.sqrt(2000000))+1
primes = [2]
for i in range(3,n,2):
    for j in primes:
        if i % j == 0:
            break
        if j*2 > i:
            primes.append(i)
            break

N, K = map(int, input().split(" "))
total = 0
memo = {}
for i in range(2, N+1):
    if count_primes(i, K):
        total += 1
        memo[i] = True
print(total)
0