結果

問題 No.458 異なる素数の和
ユーザー soisusoisu
提出日時 2021-09-17 11:42:22
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 416 ms / 2,000 ms
コード長 343 bytes
コンパイル時間 334 ms
コンパイル使用メモリ 86,996 KB
実行使用メモリ 77,064 KB
最終ジャッジ日時 2023-09-12 04:21:53
合計ジャッジ時間 6,233 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
76,040 KB
testcase_01 AC 182 ms
76,788 KB
testcase_02 AC 212 ms
76,836 KB
testcase_03 AC 113 ms
76,824 KB
testcase_04 AC 119 ms
76,384 KB
testcase_05 AC 361 ms
76,716 KB
testcase_06 AC 207 ms
76,380 KB
testcase_07 AC 87 ms
76,172 KB
testcase_08 AC 363 ms
76,996 KB
testcase_09 AC 99 ms
76,648 KB
testcase_10 AC 75 ms
71,304 KB
testcase_11 AC 416 ms
77,000 KB
testcase_12 AC 75 ms
71,248 KB
testcase_13 AC 76 ms
71,400 KB
testcase_14 AC 75 ms
71,508 KB
testcase_15 AC 75 ms
71,056 KB
testcase_16 AC 103 ms
76,712 KB
testcase_17 AC 78 ms
75,868 KB
testcase_18 AC 78 ms
75,828 KB
testcase_19 AC 73 ms
71,052 KB
testcase_20 AC 80 ms
76,040 KB
testcase_21 AC 75 ms
71,596 KB
testcase_22 AC 77 ms
71,504 KB
testcase_23 AC 77 ms
75,900 KB
testcase_24 AC 80 ms
75,836 KB
testcase_25 AC 75 ms
71,232 KB
testcase_26 AC 79 ms
75,796 KB
testcase_27 AC 200 ms
76,712 KB
testcase_28 AC 408 ms
77,064 KB
testcase_29 AC 93 ms
76,516 KB
testcase_30 AC 159 ms
76,652 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