結果

問題 No.458 異なる素数の和
ユーザー NoaSaberNoaSaber
提出日時 2021-04-17 15:22:41
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 626 bytes
コンパイル時間 282 ms
コンパイル使用メモリ 87,252 KB
実行使用メモリ 79,068 KB
最終ジャッジ日時 2023-09-17 00:34:30
合計ジャッジ時間 6,641 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
76,080 KB
testcase_01 AC 210 ms
76,960 KB
testcase_02 AC 251 ms
76,972 KB
testcase_03 AC 104 ms
77,104 KB
testcase_04 AC 113 ms
77,144 KB
testcase_05 AC 507 ms
77,248 KB
testcase_06 AC 235 ms
77,204 KB
testcase_07 AC 70 ms
76,176 KB
testcase_08 AC 456 ms
77,356 KB
testcase_09 AC 83 ms
77,116 KB
testcase_10 RE -
testcase_11 AC 531 ms
77,060 KB
testcase_12 AC 60 ms
71,468 KB
testcase_13 AC 60 ms
71,340 KB
testcase_14 AC 59 ms
71,396 KB
testcase_15 AC 60 ms
71,372 KB
testcase_16 AC 90 ms
77,132 KB
testcase_17 AC 64 ms
76,000 KB
testcase_18 AC 64 ms
75,808 KB
testcase_19 AC 60 ms
71,472 KB
testcase_20 AC 64 ms
76,188 KB
testcase_21 AC 60 ms
71,396 KB
testcase_22 AC 60 ms
71,356 KB
testcase_23 AC 66 ms
75,804 KB
testcase_24 AC 68 ms
76,040 KB
testcase_25 AC 62 ms
71,512 KB
testcase_26 AC 67 ms
75,656 KB
testcase_27 AC 228 ms
77,172 KB
testcase_28 AC 540 ms
77,276 KB
testcase_29 AC 78 ms
76,324 KB
testcase_30 AC 176 ms
76,900 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N=int(input())
def eratosthenes(n):
    if n==2:
        return [2]
    prime = [2]
    limit = int(n**0.5)
    data = [i + 1 for i in range(2, n, 2)]
    while True:
        p = data[0]#まだ残ってる中での最小の素数
        if limit <= p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]#リスト内包表記で消してる
prime=eratosthenes(N)
dp=[-1]*(N+1)
dp[0]=0
for i in prime:
    for j in reversed(range(N+1)):
        if dp[j]==-1:
            continue
        if j+i<=N:
            dp[j+i]=max(dp[j+i],dp[j]+1)
print(dp[-1] if dp[-1]!=-1 else -1)
0