結果

問題 No.458 異なる素数の和
ユーザー cshimegi
提出日時 2020-12-05 14:43:26
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 898 ms / 2,000 ms
コード長 414 bytes
コンパイル時間 366 ms
コンパイル使用メモリ 81,952 KB
実行使用メモリ 421,944 KB
最終ジャッジ日時 2024-09-15 17:35:59
合計ジャッジ時間 7,650 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
s = [1]*(n+1)
p = 2
while p*p <= n:
    if s[p]:
        for i in range(p*2, n+1, p):
            s[i] = 0
    p += 1

_ = range(n+1)
__ = [0]+[-1]*n
dp = [__*1]
add = dp.append
i = 0

for k in range(2, n+1):
    if s[k]:
        add(__*1)
        for w in _:
            dp[i][w] = max(1+dp[i-1][w-k], dp[i-1][w]) if k <= w and dp[i-1][w-k] != -1 else dp[i-1][w]
        i += 1

print(dp[i-1][n])
0