結果

問題 No.458 異なる素数の和
ユーザー 👑 H20H20
提出日時 2021-01-13 10:38:47
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 583 ms / 2,000 ms
コード長 521 bytes
コンパイル時間 293 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 76,416 KB
最終ジャッジ日時 2024-05-01 20:24:57
合計ジャッジ時間 5,568 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
60,672 KB
testcase_01 AC 206 ms
76,408 KB
testcase_02 AC 254 ms
75,832 KB
testcase_03 AC 92 ms
75,904 KB
testcase_04 AC 103 ms
76,160 KB
testcase_05 AC 493 ms
76,032 KB
testcase_06 AC 241 ms
75,964 KB
testcase_07 AC 50 ms
63,232 KB
testcase_08 AC 499 ms
75,940 KB
testcase_09 AC 69 ms
75,776 KB
testcase_10 AC 37 ms
51,840 KB
testcase_11 AC 583 ms
76,292 KB
testcase_12 AC 37 ms
52,096 KB
testcase_13 AC 37 ms
51,840 KB
testcase_14 AC 37 ms
52,480 KB
testcase_15 AC 37 ms
52,096 KB
testcase_16 AC 79 ms
75,648 KB
testcase_17 AC 41 ms
58,864 KB
testcase_18 AC 40 ms
57,976 KB
testcase_19 AC 37 ms
52,224 KB
testcase_20 AC 41 ms
59,008 KB
testcase_21 AC 37 ms
52,224 KB
testcase_22 AC 38 ms
52,224 KB
testcase_23 AC 44 ms
59,008 KB
testcase_24 AC 41 ms
59,392 KB
testcase_25 AC 37 ms
52,096 KB
testcase_26 AC 40 ms
57,856 KB
testcase_27 AC 230 ms
76,416 KB
testcase_28 AC 565 ms
75,988 KB
testcase_29 AC 59 ms
70,656 KB
testcase_30 AC 171 ms
75,776 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)
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