結果

問題 No.458 異なる素数の和
ユーザー soisusoisu
提出日時 2021-09-18 10:20:38
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 411 ms / 2,000 ms
コード長 343 bytes
コンパイル時間 745 ms
コンパイル使用メモリ 87,116 KB
実行使用メモリ 76,804 KB
最終ジャッジ日時 2023-09-12 19:47:03
合計ジャッジ時間 6,582 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
75,952 KB
testcase_01 AC 180 ms
76,120 KB
testcase_02 AC 209 ms
76,216 KB
testcase_03 AC 108 ms
76,432 KB
testcase_04 AC 113 ms
76,304 KB
testcase_05 AC 356 ms
76,408 KB
testcase_06 AC 204 ms
76,588 KB
testcase_07 AC 83 ms
76,116 KB
testcase_08 AC 360 ms
76,804 KB
testcase_09 AC 95 ms
76,580 KB
testcase_10 AC 69 ms
71,320 KB
testcase_11 AC 411 ms
76,800 KB
testcase_12 AC 73 ms
71,068 KB
testcase_13 AC 70 ms
71,152 KB
testcase_14 AC 70 ms
71,348 KB
testcase_15 AC 70 ms
71,344 KB
testcase_16 AC 100 ms
76,724 KB
testcase_17 AC 76 ms
75,604 KB
testcase_18 AC 73 ms
75,780 KB
testcase_19 AC 70 ms
71,108 KB
testcase_20 AC 76 ms
75,964 KB
testcase_21 AC 74 ms
71,192 KB
testcase_22 AC 72 ms
71,152 KB
testcase_23 AC 75 ms
75,572 KB
testcase_24 AC 78 ms
75,860 KB
testcase_25 AC 72 ms
71,328 KB
testcase_26 AC 74 ms
75,472 KB
testcase_27 AC 194 ms
76,520 KB
testcase_28 AC 404 ms
76,540 KB
testcase_29 AC 89 ms
76,388 KB
testcase_30 AC 154 ms
76,588 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N=int(input())
p=[True]*(N+1)
p[0]=p[1]=False
for i in range(2,N+1):
    for j in range(i*i,N+1,i):
        p[j]=False

prime=[]
for i in range(N+1):
    if p[i]:
        prime.append(i)

dp=[-1]*(N+1)
dp[0]=0

for u in prime:
    for i in range(N,-1,-1):
        if u+i<=N and dp[i]!=-1:
            dp[u+i]=max(dp[u+i],dp[i]+1)

print(dp[N])
0