結果

問題 No.458 異なる素数の和
ユーザー convexineqconvexineq
提出日時 2021-03-30 04:41:05
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 271 ms / 2,000 ms
コード長 550 bytes
コンパイル時間 539 ms
コンパイル使用メモリ 86,940 KB
実行使用メモリ 77,152 KB
最終ジャッジ日時 2023-08-20 01:55:48
合計ジャッジ時間 5,959 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
76,100 KB
testcase_01 AC 138 ms
76,776 KB
testcase_02 AC 153 ms
76,816 KB
testcase_03 AC 97 ms
76,924 KB
testcase_04 AC 101 ms
76,508 KB
testcase_05 AC 239 ms
77,152 KB
testcase_06 AC 150 ms
77,076 KB
testcase_07 AC 81 ms
76,280 KB
testcase_08 AC 240 ms
77,036 KB
testcase_09 AC 87 ms
76,448 KB
testcase_10 AC 72 ms
71,624 KB
testcase_11 AC 271 ms
77,132 KB
testcase_12 AC 73 ms
71,880 KB
testcase_13 AC 73 ms
71,676 KB
testcase_14 AC 73 ms
71,680 KB
testcase_15 AC 73 ms
71,836 KB
testcase_16 AC 92 ms
76,876 KB
testcase_17 AC 74 ms
71,668 KB
testcase_18 AC 74 ms
71,672 KB
testcase_19 AC 74 ms
71,712 KB
testcase_20 AC 78 ms
76,184 KB
testcase_21 AC 75 ms
71,608 KB
testcase_22 AC 75 ms
71,636 KB
testcase_23 AC 77 ms
76,316 KB
testcase_24 AC 78 ms
76,004 KB
testcase_25 AC 73 ms
71,692 KB
testcase_26 AC 75 ms
71,600 KB
testcase_27 AC 148 ms
76,552 KB
testcase_28 AC 268 ms
77,124 KB
testcase_29 AC 86 ms
76,464 KB
testcase_30 AC 125 ms
76,688 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def Eratosthenes(N): #N以下の素数のリストを返す
    #iが素数のときis_prime_list[i]=1,それ以外は0
    N+=1
    is_prime_list = [True]*N
    m = int(N**0.5)+1
    for i in range(3,m,2):
        if is_prime_list[i]:
            is_prime_list[i*i::2*i]=[False]*((N-i*i-1)//(2*i)+1)
    return [2] + [i for i in range(3,N,2) if is_prime_list[i]]

n = int(input())

dp = [-1]*(n+1)
dp[0] = 0
for p in Eratosthenes(n):
    for i in range(n+1-p)[::-1]:
        if dp[i] != -1:
            dp[i+p] = max(dp[i+p],dp[i]+1)
print(dp[-1])
0