結果

問題 No.458 異なる素数の和
ユーザー qibqib
提出日時 2022-12-05 03:12:13
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 479 bytes
コンパイル時間 256 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 65,280 KB
最終ジャッジ日時 2024-04-20 07:25:25
合計ジャッジ時間 3,505 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
58,624 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 59 ms
64,128 KB
testcase_04 AC 64 ms
64,908 KB
testcase_05 AC 218 ms
64,896 KB
testcase_06 WA -
testcase_07 AC 42 ms
59,776 KB
testcase_08 AC 229 ms
64,896 KB
testcase_09 AC 52 ms
62,464 KB
testcase_10 AC 34 ms
52,096 KB
testcase_11 AC 252 ms
65,280 KB
testcase_12 AC 34 ms
52,352 KB
testcase_13 AC 34 ms
51,968 KB
testcase_14 AC 33 ms
51,968 KB
testcase_15 AC 33 ms
51,968 KB
testcase_16 AC 55 ms
63,360 KB
testcase_17 AC 34 ms
51,968 KB
testcase_18 AC 34 ms
51,840 KB
testcase_19 AC 33 ms
51,584 KB
testcase_20 AC 36 ms
57,600 KB
testcase_21 AC 32 ms
52,352 KB
testcase_22 AC 32 ms
52,224 KB
testcase_23 AC 36 ms
57,728 KB
testcase_24 AC 35 ms
57,344 KB
testcase_25 AC 33 ms
51,968 KB
testcase_26 AC 33 ms
52,096 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 46 ms
61,824 KB
testcase_30 WA -
権限があれば一括ダウンロードができます

ソースコード

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 or not dp[y + x] is None:
      continue
    dp[y + x] = dp[y] + 1

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