結果

問題 No.458 異なる素数の和
ユーザー 👑 H20H20
提出日時 2021-01-13 10:36:05
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 523 bytes
コンパイル時間 228 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 76,544 KB
最終ジャッジ日時 2024-05-01 20:22:45
合計ジャッジ時間 5,786 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
60,544 KB
testcase_01 AC 213 ms
76,032 KB
testcase_02 AC 259 ms
76,032 KB
testcase_03 AC 93 ms
75,904 KB
testcase_04 AC 102 ms
76,416 KB
testcase_05 AC 500 ms
76,544 KB
testcase_06 AC 243 ms
76,160 KB
testcase_07 AC 49 ms
62,976 KB
testcase_08 AC 502 ms
76,160 KB
testcase_09 AC 72 ms
75,776 KB
testcase_10 AC 37 ms
52,096 KB
testcase_11 AC 589 ms
76,244 KB
testcase_12 AC 37 ms
51,840 KB
testcase_13 WA -
testcase_14 AC 36 ms
52,224 KB
testcase_15 AC 37 ms
52,224 KB
testcase_16 AC 78 ms
76,288 KB
testcase_17 AC 42 ms
58,496 KB
testcase_18 AC 41 ms
57,984 KB
testcase_19 AC 41 ms
52,224 KB
testcase_20 AC 43 ms
59,648 KB
testcase_21 AC 37 ms
51,968 KB
testcase_22 AC 37 ms
52,096 KB
testcase_23 AC 41 ms
58,624 KB
testcase_24 AC 42 ms
59,264 KB
testcase_25 AC 38 ms
52,352 KB
testcase_26 AC 40 ms
57,984 KB
testcase_27 AC 236 ms
76,076 KB
testcase_28 AC 576 ms
76,160 KB
testcase_29 AC 61 ms
70,784 KB
testcase_30 AC 167 ms
75,648 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def sieve(n):
    is_prime = [True for _ in range(n+1)]
    is_prime[0] = False

    for i in range(2, n+1):
        if is_prime[i-1]:
            j = 2 * i
            while j <= n:
                is_prime[j-1] = False
                j += i
    table = [ i for i in range(1, n+1) if is_prime[i-1]]
    return is_prime, table

N = int(input())
_,table=sieve(N-1)
DP=[-1]*(N+1)
DP[0]=0
for t in table:
    for i in reversed(range(N)):
        if DP[i]>=0 and i+t<=N:
            DP[i+t] = max(DP[i+t],DP[i]+1)
print(DP[N])
0