結果

問題 No.458 異なる素数の和
ユーザー titiatitia
提出日時 2023-08-30 04:31:46
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 276 ms / 2,000 ms
コード長 532 bytes
コンパイル時間 360 ms
コンパイル使用メモリ 87,088 KB
実行使用メモリ 76,976 KB
最終ジャッジ日時 2023-08-30 04:31:54
合計ジャッジ時間 5,364 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
75,944 KB
testcase_01 AC 134 ms
76,688 KB
testcase_02 AC 156 ms
76,176 KB
testcase_03 AC 94 ms
76,480 KB
testcase_04 AC 103 ms
76,400 KB
testcase_05 AC 238 ms
76,836 KB
testcase_06 AC 148 ms
76,564 KB
testcase_07 AC 77 ms
76,096 KB
testcase_08 AC 239 ms
76,812 KB
testcase_09 AC 87 ms
76,572 KB
testcase_10 AC 72 ms
71,408 KB
testcase_11 AC 276 ms
76,724 KB
testcase_12 AC 73 ms
71,372 KB
testcase_13 AC 72 ms
71,624 KB
testcase_14 AC 73 ms
71,384 KB
testcase_15 AC 73 ms
71,480 KB
testcase_16 AC 91 ms
76,688 KB
testcase_17 AC 73 ms
71,436 KB
testcase_18 AC 75 ms
71,508 KB
testcase_19 AC 74 ms
71,304 KB
testcase_20 AC 79 ms
75,776 KB
testcase_21 AC 75 ms
71,368 KB
testcase_22 AC 77 ms
71,636 KB
testcase_23 AC 78 ms
76,088 KB
testcase_24 AC 78 ms
75,664 KB
testcase_25 AC 75 ms
71,384 KB
testcase_26 AC 75 ms
71,796 KB
testcase_27 AC 147 ms
76,552 KB
testcase_28 AC 271 ms
76,976 KB
testcase_29 AC 87 ms
76,588 KB
testcase_30 AC 125 ms
76,272 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N=int(input())

x=N
import math 
L=math.floor(math.sqrt(x)) # 平方根を求める

Primelist=[i for i in range(x+1)]
Primelist[1]=0 # 1は素数でないので0にする.
 
for i in Primelist:
    if i>L:
        break
    if i==0:
        continue
    for j in range(2*i,x+1,i):
        Primelist[j]=0

Primes=[Primelist[j] for j in range(x+1) if Primelist[j]!=0]

DP=[-1<<60]*(N+1)
DP[0]=0

for p in Primes:
    for i in range(N-p,-1,-1):
        DP[i+p]=max(DP[i+p],DP[i]+1)

if DP[-1]<0:
    print(-1)
else:
    print(DP[-1])
0