結果

問題 No.458 異なる素数の和
ユーザー takakintakakin
提出日時 2020-03-28 20:26:57
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 383 ms / 2,000 ms
コード長 485 bytes
コンパイル時間 1,358 ms
コンパイル使用メモリ 87,136 KB
実行使用メモリ 77,540 KB
最終ジャッジ日時 2023-08-30 18:10:35
合計ジャッジ時間 5,616 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
76,292 KB
testcase_01 AC 168 ms
76,876 KB
testcase_02 AC 196 ms
77,056 KB
testcase_03 AC 99 ms
77,032 KB
testcase_04 AC 106 ms
76,868 KB
testcase_05 AC 332 ms
76,880 KB
testcase_06 AC 184 ms
77,068 KB
testcase_07 AC 75 ms
76,292 KB
testcase_08 AC 335 ms
77,360 KB
testcase_09 AC 88 ms
76,864 KB
testcase_10 AC 66 ms
71,332 KB
testcase_11 AC 383 ms
76,928 KB
testcase_12 AC 69 ms
71,484 KB
testcase_13 AC 69 ms
71,644 KB
testcase_14 AC 70 ms
71,436 KB
testcase_15 AC 69 ms
71,616 KB
testcase_16 AC 93 ms
76,944 KB
testcase_17 AC 70 ms
76,256 KB
testcase_18 AC 71 ms
76,228 KB
testcase_19 AC 69 ms
71,872 KB
testcase_20 AC 74 ms
76,376 KB
testcase_21 AC 66 ms
71,972 KB
testcase_22 AC 69 ms
71,372 KB
testcase_23 AC 73 ms
76,352 KB
testcase_24 AC 73 ms
76,500 KB
testcase_25 AC 69 ms
71,516 KB
testcase_26 AC 70 ms
76,056 KB
testcase_27 AC 182 ms
76,644 KB
testcase_28 AC 377 ms
77,540 KB
testcase_29 AC 82 ms
76,884 KB
testcase_30 AC 144 ms
77,160 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input=lambda: sys.stdin.readline().rstrip()
n=int(input())
def primes(n):
  is_prime=[True]*(n+1)
  is_prime[0]=False
  is_prime[1]=False
  for i in range(2,int(n**0.5)+1):
    if not is_prime[i]:
      continue
    for j in range(i*2,n+1,i):
      is_prime[j]=False
  return [i for i in range(n+1) if is_prime[i]]
P=primes(n)
m=len(P)
DP=[0]*(n+1)
DP[0]=1
for p in P:
  for i in range(n+1)[::-1]:
    if i>=p and DP[i-p]>0:
      DP[i]=max(DP[i],DP[i-p]+1)
print(DP[n]-1)

0