結果

問題 No.458 異なる素数の和
ユーザー 👑 rin204rin204
提出日時 2022-07-01 13:54:33
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 220 ms / 2,000 ms
コード長 449 bytes
コンパイル時間 135 ms
コンパイル使用メモリ 82,720 KB
実行使用メモリ 64,752 KB
最終ジャッジ日時 2024-05-04 08:07:39
合計ジャッジ時間 3,633 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
61,696 KB
testcase_01 AC 97 ms
64,000 KB
testcase_02 AC 112 ms
64,256 KB
testcase_03 AC 61 ms
63,744 KB
testcase_04 AC 64 ms
63,872 KB
testcase_05 AC 190 ms
64,128 KB
testcase_06 AC 109 ms
64,752 KB
testcase_07 AC 47 ms
61,824 KB
testcase_08 AC 186 ms
64,256 KB
testcase_09 AC 56 ms
64,256 KB
testcase_10 AC 43 ms
60,032 KB
testcase_11 AC 220 ms
64,384 KB
testcase_12 AC 45 ms
59,776 KB
testcase_13 AC 45 ms
59,776 KB
testcase_14 AC 45 ms
59,520 KB
testcase_15 AC 45 ms
59,904 KB
testcase_16 AC 57 ms
64,000 KB
testcase_17 AC 52 ms
59,904 KB
testcase_18 AC 44 ms
60,032 KB
testcase_19 AC 43 ms
59,392 KB
testcase_20 AC 44 ms
61,056 KB
testcase_21 AC 44 ms
59,520 KB
testcase_22 AC 44 ms
59,520 KB
testcase_23 AC 46 ms
60,800 KB
testcase_24 AC 46 ms
60,544 KB
testcase_25 AC 43 ms
59,776 KB
testcase_26 AC 44 ms
59,776 KB
testcase_27 AC 104 ms
64,128 KB
testcase_28 AC 216 ms
64,640 KB
testcase_29 AC 51 ms
63,744 KB
testcase_30 AC 83 ms
64,000 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = 200000
isprime = [True] * N
isprime[0] = isprime[1] = False
for i in range(2, int(N ** 0.5 + 1)):
    if not isprime[i]:
        continue
    for j in range(i * i, N, i):
        isprime[j] = False

n = int(input())
dp = [-1 << 30] * (n + 1)
dp[0] = 0
primes = [i for i, tf in enumerate(isprime[:n + 1]) if tf]
for p in primes:
    for i in range(n, p - 1, -1):
        dp[i] = max(dp[i], dp[i - p] + 1)
if dp[n] < 0:
    dp[n] = -1
print(dp[n])
0