結果

問題 No.458 異なる素数の和
ユーザー syunsukesyunsuke
提出日時 2019-04-18 22:06:43
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 597 ms / 2,000 ms
コード長 516 bytes
コンパイル時間 255 ms
コンパイル使用メモリ 81,836 KB
実行使用メモリ 66,784 KB
最終ジャッジ日時 2023-10-23 16:24:49
合計ジャッジ時間 5,705 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
61,680 KB
testcase_01 AC 208 ms
66,468 KB
testcase_02 AC 261 ms
66,468 KB
testcase_03 AC 88 ms
66,468 KB
testcase_04 AC 99 ms
66,468 KB
testcase_05 AC 506 ms
66,752 KB
testcase_06 AC 244 ms
66,468 KB
testcase_07 AC 48 ms
61,904 KB
testcase_08 AC 509 ms
66,756 KB
testcase_09 AC 61 ms
64,344 KB
testcase_10 AC 36 ms
53,584 KB
testcase_11 AC 597 ms
66,784 KB
testcase_12 AC 37 ms
53,584 KB
testcase_13 AC 36 ms
53,584 KB
testcase_14 AC 38 ms
53,584 KB
testcase_15 AC 37 ms
53,584 KB
testcase_16 AC 72 ms
66,464 KB
testcase_17 AC 39 ms
59,596 KB
testcase_18 AC 40 ms
59,596 KB
testcase_19 AC 37 ms
53,584 KB
testcase_20 AC 41 ms
59,616 KB
testcase_21 AC 36 ms
53,584 KB
testcase_22 AC 37 ms
53,584 KB
testcase_23 AC 41 ms
59,604 KB
testcase_24 AC 43 ms
59,616 KB
testcase_25 AC 37 ms
53,584 KB
testcase_26 AC 40 ms
59,596 KB
testcase_27 AC 235 ms
66,468 KB
testcase_28 AC 588 ms
66,780 KB
testcase_29 AC 58 ms
64,328 KB
testcase_30 AC 166 ms
66,468 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N=int(input())

SO=[1 for i in range(N+1)]
SO[0]=0
SO[1]=0
for i in range(2,N+1):
    if SO[i]==1:
        for j in range(2,N+1):
            if i*j>N:
                break
            else:
                SO[i*j]=0
#print(SO)
L=[]
for i in range(len(SO)):
    if SO[i]==1:
        L.append(i)
#print(L)
dp=[-1 for i in range(N+1)]
dp[0]=0
for i in range(len(L)):
    for j in range(N+1):
        if L[i]<=j and dp[N-j]>=0:
            if dp[N-j+L[i]]<dp[N-j]+1:
                dp[N-j+L[i]]=dp[N-j]+1
print(dp[N])
0