結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 791 ms
431,180 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 781 ms
431,596 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 518 ms
431,416 KB
testcase_11 AC 787 ms
431,760 KB
testcase_12 AC 778 ms
431,584 KB
testcase_13 WA -
testcase_14 AC 785 ms
431,372 KB
testcase_15 AC 777 ms
431,376 KB
testcase_16 AC 821 ms
431,588 KB
testcase_17 AC 779 ms
431,384 KB
testcase_18 AC 791 ms
431,220 KB
testcase_19 WA -
testcase_20 AC 801 ms
431,280 KB
testcase_21 AC 781 ms
431,444 KB
testcase_22 AC 760 ms
431,452 KB
testcase_23 WA -
testcase_24 AC 789 ms
431,176 KB
testcase_25 AC 771 ms
431,380 KB
testcase_26 AC 787 ms
431,348 KB
testcase_27 AC 794 ms
431,384 KB
testcase_28 AC 801 ms
431,500 KB
testcase_29 WA -
testcase_30 AC 801 ms
431,172 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(2,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