結果

問題 No.458 異なる素数の和
ユーザー ああああ
提出日時 2023-01-16 11:03:02
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,238 ms / 2,000 ms
コード長 694 bytes
コンパイル時間 269 ms
コンパイル使用メモリ 86,948 KB
実行使用メモリ 431,192 KB
最終ジャッジ日時 2023-08-28 23:38:19
合計ジャッジ時間 11,255 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
76,180 KB
testcase_01 AC 434 ms
177,900 KB
testcase_02 AC 563 ms
204,444 KB
testcase_03 AC 168 ms
90,464 KB
testcase_04 AC 188 ms
106,100 KB
testcase_05 AC 1,078 ms
371,884 KB
testcase_06 AC 525 ms
201,496 KB
testcase_07 AC 82 ms
76,052 KB
testcase_08 AC 1,033 ms
374,300 KB
testcase_09 AC 103 ms
76,324 KB
testcase_10 AC 70 ms
71,448 KB
testcase_11 AC 1,238 ms
431,192 KB
testcase_12 AC 75 ms
71,272 KB
testcase_13 AC 70 ms
71,524 KB
testcase_14 AC 70 ms
71,608 KB
testcase_15 AC 70 ms
71,356 KB
testcase_16 AC 133 ms
89,916 KB
testcase_17 AC 74 ms
76,020 KB
testcase_18 AC 74 ms
76,092 KB
testcase_19 AC 70 ms
71,616 KB
testcase_20 AC 77 ms
75,944 KB
testcase_21 AC 72 ms
71,116 KB
testcase_22 AC 70 ms
71,120 KB
testcase_23 AC 77 ms
75,984 KB
testcase_24 AC 76 ms
76,084 KB
testcase_25 AC 71 ms
71,324 KB
testcase_26 AC 76 ms
75,784 KB
testcase_27 AC 477 ms
181,556 KB
testcase_28 AC 1,193 ms
423,164 KB
testcase_29 AC 97 ms
76,564 KB
testcase_30 AC 328 ms
136,296 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N=int(input())

def list_primes(limit):
    primes = []
    is_prime = [True] * (limit + 1)
    is_prime[0] = False
    is_prime[1] = False

    for p in range (0, limit + 1):
        if not is_prime[p]:
            continue
        primes.append(p)
        for i in range(p*p, limit + 1, p):
            is_prime[i] = False

    return primes

primes=list_primes(N)
dp=[[-10**10]*(N+1) for _ in range(len(primes)+1)]
dp[0][0]=0
for i in range(1,len(primes)+1):
    for j in range(N+1):
        dp[i][j]=max(dp[i][j],dp[i-1][j])
        if j-primes[i-1]>=0:
            dp[i][j]=max(dp[i][j],dp[i-1][j-primes[i-1]]+1)

if dp[len(primes)][N]<0:
    print(-1)
else:
    print(dp[len(primes)][N])
0