結果

問題 No.458 異なる素数の和
ユーザー qibqib
提出日時 2022-12-05 03:16:55
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 417 ms / 2,000 ms
コード長 537 bytes
コンパイル時間 272 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 66,304 KB
最終ジャッジ日時 2024-04-20 07:27:23
合計ジャッジ時間 4,540 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
58,880 KB
testcase_01 AC 135 ms
65,536 KB
testcase_02 AC 167 ms
65,920 KB
testcase_03 AC 79 ms
64,640 KB
testcase_04 AC 86 ms
65,408 KB
testcase_05 AC 351 ms
66,304 KB
testcase_06 AC 156 ms
65,920 KB
testcase_07 AC 53 ms
60,160 KB
testcase_08 AC 354 ms
65,664 KB
testcase_09 AC 63 ms
63,104 KB
testcase_10 AC 40 ms
51,712 KB
testcase_11 AC 417 ms
66,304 KB
testcase_12 AC 41 ms
51,712 KB
testcase_13 AC 41 ms
52,224 KB
testcase_14 AC 40 ms
51,712 KB
testcase_15 AC 40 ms
51,968 KB
testcase_16 AC 71 ms
64,000 KB
testcase_17 AC 41 ms
51,840 KB
testcase_18 AC 41 ms
51,968 KB
testcase_19 AC 39 ms
51,840 KB
testcase_20 AC 45 ms
57,984 KB
testcase_21 AC 40 ms
51,712 KB
testcase_22 AC 40 ms
51,840 KB
testcase_23 AC 44 ms
57,728 KB
testcase_24 AC 45 ms
58,112 KB
testcase_25 AC 40 ms
51,968 KB
testcase_26 AC 40 ms
51,968 KB
testcase_27 AC 150 ms
65,920 KB
testcase_28 AC 404 ms
66,048 KB
testcase_29 AC 59 ms
62,336 KB
testcase_30 AC 118 ms
65,280 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())

prime = [True for _ in range(n + 1)]
prime[0] = False
prime[1] = False
for x in range(2, n + 1):
  if not prime[x]:
    continue
  for y in range(2 * x, n + 1, x):
    prime[y] = False

dp = [None for _ in range(n + 1)]
dp[0] = 0
for x in range(2, n + 1):
  if not prime[x]:
    continue
  for y in range(n - x, -1, -1):
    if dp[y] is None:
      continue
    if dp[y + x] is None:
      dp[y + x] = dp[y] + 1
    else:
      dp[y + x] = max(dp[y + x], dp[y] + 1)

if dp[n] is None:
  print("-1")
else:
  print(dp[n])
0