結果

問題 No.458 異なる素数の和
ユーザー h_nosonh_noson
提出日時 2017-01-26 13:30:36
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 324 ms / 2,000 ms
コード長 440 bytes
コンパイル時間 322 ms
コンパイル使用メモリ 87,064 KB
実行使用メモリ 76,684 KB
最終ジャッジ日時 2023-09-18 15:17:50
合計ジャッジ時間 5,436 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
75,940 KB
testcase_01 AC 154 ms
76,416 KB
testcase_02 AC 179 ms
76,600 KB
testcase_03 AC 104 ms
76,500 KB
testcase_04 AC 106 ms
76,480 KB
testcase_05 AC 284 ms
76,684 KB
testcase_06 AC 169 ms
76,372 KB
testcase_07 AC 81 ms
75,880 KB
testcase_08 AC 286 ms
76,660 KB
testcase_09 AC 90 ms
76,532 KB
testcase_10 AC 71 ms
71,460 KB
testcase_11 AC 324 ms
76,576 KB
testcase_12 AC 74 ms
71,392 KB
testcase_13 AC 74 ms
71,180 KB
testcase_14 AC 71 ms
71,180 KB
testcase_15 AC 73 ms
71,292 KB
testcase_16 AC 92 ms
76,520 KB
testcase_17 AC 72 ms
71,392 KB
testcase_18 AC 74 ms
71,036 KB
testcase_19 AC 73 ms
71,184 KB
testcase_20 AC 78 ms
75,540 KB
testcase_21 AC 73 ms
71,176 KB
testcase_22 AC 79 ms
71,400 KB
testcase_23 AC 74 ms
75,752 KB
testcase_24 AC 75 ms
75,840 KB
testcase_25 AC 72 ms
71,560 KB
testcase_26 AC 75 ms
71,284 KB
testcase_27 AC 166 ms
76,256 KB
testcase_28 AC 319 ms
76,576 KB
testcase_29 AC 88 ms
76,348 KB
testcase_30 AC 136 ms
76,568 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def primes(n):
    is_p = [True for i in range(n+1)]
    i = 2
    while i * i <= n:
        if is_p[i]:
            for j in range(i*i,n+1,i):
                is_p[j] = False
        i += 1
    return [i for i in range(2,n+1) if is_p[i]]

n = int(input())
p = primes(n)
dp = [-1] * (n+1)
dp[0] = 0
for i in range(len(p)):
    for j in range(n,p[i]-1,-1):
        if dp[j-p[i]] >= 0:
            dp[j] = max(dp[j],dp[j-p[i]]+1)
print(dp[n])
0