結果

問題 No.458 異なる素数の和
ユーザー kotatsuinu5kotatsuinu5
提出日時 2020-11-28 16:35:26
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 749 bytes
コンパイル時間 382 ms
コンパイル使用メモリ 87,196 KB
実行使用メモリ 431,832 KB
最終ジャッジ日時 2023-10-10 00:41:51
合計ジャッジ時間 26,493 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 777 ms
431,108 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 800 ms
431,340 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 538 ms
431,364 KB
testcase_11 AC 777 ms
431,772 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 755 ms
431,436 KB
testcase_16 AC 790 ms
431,456 KB
testcase_17 AC 781 ms
431,180 KB
testcase_18 AC 761 ms
431,276 KB
testcase_19 AC 768 ms
431,636 KB
testcase_20 AC 769 ms
431,516 KB
testcase_21 AC 753 ms
431,376 KB
testcase_22 AC 770 ms
431,540 KB
testcase_23 WA -
testcase_24 AC 774 ms
431,284 KB
testcase_25 AC 777 ms
431,368 KB
testcase_26 AC 764 ms
431,628 KB
testcase_27 AC 784 ms
431,456 KB
testcase_28 AC 808 ms
431,832 KB
testcase_29 WA -
testcase_30 AC 800 ms
431,420 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import math
N=int(input())
S=[]

maxv=20010
def eratos(n):
    isprime=[True]*(n+1)
    isprime[0]=False
    isprime[1]=False
    for i in range(2,int(math.sqrt(n))+1):
        if isprime[i]==True:
            j=i+i
            while j<=n:
                isprime[j] =False
                j=j+i

    for i in range(n+1):
        if isprime[i]==True:
            S.append(i)
    return S
    
sosu=eratos(maxv)
#print(sosu)
#print(len(sosu))


DP = [[-1]*(maxv) for i in range(len(S)+1)] 

for i in range(len(S)):
    for j in range(maxv):
        if DP[i][j]+S[i]<= N and j+S[i]<=N:
            DP[i+1][j+S[i]]=DP[i][j]+1

ans=-1
for i in range(len(S)):
    if DP[i][N]>ans:
        ans=DP[i][N]
if ans>0:
    
    print(ans+1)
else:
    print(-1)
0