結果

問題 No.458 異なる素数の和
ユーザー DrDrpilotDrDrpilot
提出日時 2022-06-21 16:48:45
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,476 ms / 2,000 ms
コード長 733 bytes
コンパイル時間 189 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 415,488 KB
最終ジャッジ日時 2024-04-22 11:20:32
合計ジャッジ時間 10,232 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 57 ms
62,592 KB
testcase_01 AC 471 ms
160,076 KB
testcase_02 AC 611 ms
205,696 KB
testcase_03 AC 147 ms
91,152 KB
testcase_04 AC 168 ms
91,136 KB
testcase_05 AC 1,238 ms
355,712 KB
testcase_06 AC 566 ms
182,912 KB
testcase_07 AC 54 ms
63,232 KB
testcase_08 AC 1,240 ms
358,528 KB
testcase_09 AC 79 ms
70,784 KB
testcase_10 AC 39 ms
52,096 KB
testcase_11 AC 1,476 ms
415,488 KB
testcase_12 AC 39 ms
52,480 KB
testcase_13 AC 38 ms
52,352 KB
testcase_14 AC 39 ms
52,480 KB
testcase_15 AC 39 ms
52,736 KB
testcase_16 AC 121 ms
88,320 KB
testcase_17 AC 43 ms
58,496 KB
testcase_18 AC 45 ms
59,392 KB
testcase_19 AC 40 ms
52,608 KB
testcase_20 AC 47 ms
60,288 KB
testcase_21 AC 40 ms
52,352 KB
testcase_22 AC 40 ms
52,864 KB
testcase_23 AC 46 ms
60,000 KB
testcase_24 AC 46 ms
60,032 KB
testcase_25 AC 39 ms
52,640 KB
testcase_26 AC 43 ms
58,752 KB
testcase_27 AC 542 ms
182,632 KB
testcase_28 AC 1,252 ms
407,808 KB
testcase_29 AC 66 ms
67,200 KB
testcase_30 AC 356 ms
137,428 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def Eratosthenes(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]]

def main():
    n=int(input())
    lis=Eratosthenes(n)
    N=len(lis)
    dp=[[-1]*(n+1) for _ in range(1+N)]
    dp[0][0]=0
    for i in range(N):
        num=lis[i]
        for j in range(n+1):
            if dp[i][j]<0:
                continue
            if j+num<=n:
                dp[i+1][j+num]=max(dp[i+1][j+num],dp[i][j]+1)
            dp[i+1][j]=max(dp[i+1][j],dp[i][j])
    print(dp[N][n])
if __name__=='__main__':
    main()
0