結果

問題 No.458 異なる素数の和
ユーザー NoaSaberNoaSaber
提出日時 2021-04-17 15:23:30
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 616 ms / 2,000 ms
コード長 660 bytes
コンパイル時間 274 ms
コンパイル使用メモリ 87,308 KB
実行使用メモリ 77,848 KB
最終ジャッジ日時 2023-09-17 00:35:16
合計ジャッジ時間 6,859 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
76,652 KB
testcase_01 AC 238 ms
77,236 KB
testcase_02 AC 285 ms
77,524 KB
testcase_03 AC 120 ms
77,232 KB
testcase_04 AC 129 ms
77,172 KB
testcase_05 AC 530 ms
77,812 KB
testcase_06 AC 271 ms
77,656 KB
testcase_07 AC 81 ms
76,692 KB
testcase_08 AC 531 ms
77,848 KB
testcase_09 AC 95 ms
77,756 KB
testcase_10 AC 70 ms
71,264 KB
testcase_11 AC 616 ms
77,596 KB
testcase_12 AC 71 ms
71,560 KB
testcase_13 AC 69 ms
71,640 KB
testcase_14 AC 70 ms
71,568 KB
testcase_15 AC 71 ms
71,816 KB
testcase_16 AC 106 ms
77,508 KB
testcase_17 AC 74 ms
76,204 KB
testcase_18 AC 75 ms
76,456 KB
testcase_19 AC 70 ms
71,896 KB
testcase_20 AC 77 ms
76,328 KB
testcase_21 AC 72 ms
71,444 KB
testcase_22 AC 70 ms
71,676 KB
testcase_23 AC 75 ms
76,380 KB
testcase_24 AC 77 ms
76,560 KB
testcase_25 AC 71 ms
71,648 KB
testcase_26 AC 75 ms
76,148 KB
testcase_27 AC 265 ms
77,224 KB
testcase_28 AC 611 ms
77,660 KB
testcase_29 AC 89 ms
76,884 KB
testcase_30 AC 195 ms
77,524 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N=int(input())
if N==1:
    print(-1)
    exit()
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