結果

問題 No.458 異なる素数の和
ユーザー soyamashsoyamash
提出日時 2023-12-15 23:55:29
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 294 ms / 2,000 ms
コード長 503 bytes
コンパイル時間 231 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 64,808 KB
最終ジャッジ日時 2023-12-15 23:55:33
合計ジャッジ時間 3,858 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
59,796 KB
testcase_01 AC 115 ms
64,492 KB
testcase_02 AC 138 ms
64,492 KB
testcase_03 AC 67 ms
64,492 KB
testcase_04 AC 69 ms
64,492 KB
testcase_05 AC 254 ms
64,776 KB
testcase_06 AC 134 ms
64,492 KB
testcase_07 AC 42 ms
61,868 KB
testcase_08 AC 256 ms
64,780 KB
testcase_09 AC 55 ms
64,364 KB
testcase_10 AC 34 ms
53,588 KB
testcase_11 AC 294 ms
64,808 KB
testcase_12 AC 34 ms
53,588 KB
testcase_13 AC 33 ms
53,588 KB
testcase_14 AC 34 ms
53,588 KB
testcase_15 AC 36 ms
53,588 KB
testcase_16 AC 56 ms
64,496 KB
testcase_17 AC 37 ms
53,588 KB
testcase_18 AC 37 ms
53,588 KB
testcase_19 AC 36 ms
53,588 KB
testcase_20 AC 37 ms
59,780 KB
testcase_21 AC 35 ms
53,588 KB
testcase_22 AC 45 ms
53,588 KB
testcase_23 AC 38 ms
59,780 KB
testcase_24 AC 36 ms
59,780 KB
testcase_25 AC 33 ms
53,588 KB
testcase_26 AC 33 ms
53,588 KB
testcase_27 AC 127 ms
64,492 KB
testcase_28 AC 286 ms
64,804 KB
testcase_29 AC 48 ms
62,280 KB
testcase_30 AC 97 ms
64,492 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# https://yukicoder.me/problems/931
import math
N = int(input())


is_prime = [True for _ in range(N + 1)]
is_prime[0] = is_prime[1] = False
prime_list = []
for i in range(2, N + 1):
    if is_prime[i]:
        prime_list.append(i)
        for j in range(i * i, N + 1, i):
            is_prime[j] = False

dp = [-1 for _ in range(N + 1)]
dp[0] = 0
for i in prime_list:
    for j in range(N, i - 1, -1):
        if dp[j - i] != -1:
            dp[j] = max(dp[j - i] + 1, dp[j])

print(dp[N])
# print(dp)
0