結果

問題 No.458 異なる素数の和
ユーザー h_nosonh_noson
提出日時 2017-01-26 12:43:02
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 495 bytes
コンパイル時間 243 ms
コンパイル使用メモリ 87,048 KB
実行使用メモリ 123,828 KB
最終ジャッジ日時 2023-08-24 23:54:19
合計ジャッジ時間 18,963 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
75,944 KB
testcase_01 AC 844 ms
86,184 KB
testcase_02 AC 1,091 ms
92,040 KB
testcase_03 AC 236 ms
78,108 KB
testcase_04 AC 294 ms
78,344 KB
testcase_05 TLE -
testcase_06 AC 1,050 ms
91,004 KB
testcase_07 AC 86 ms
76,088 KB
testcase_08 TLE -
testcase_09 AC 130 ms
76,932 KB
testcase_10 AC 74 ms
71,332 KB
testcase_11 TLE -
testcase_12 AC 71 ms
71,168 KB
testcase_13 AC 71 ms
71,364 KB
testcase_14 AC 71 ms
71,204 KB
testcase_15 AC 70 ms
71,188 KB
testcase_16 AC 174 ms
77,284 KB
testcase_17 AC 71 ms
71,260 KB
testcase_18 AC 71 ms
71,252 KB
testcase_19 AC 71 ms
71,328 KB
testcase_20 AC 75 ms
75,792 KB
testcase_21 AC 70 ms
71,340 KB
testcase_22 AC 71 ms
71,340 KB
testcase_23 AC 76 ms
76,028 KB
testcase_24 AC 75 ms
75,632 KB
testcase_25 AC 71 ms
70,932 KB
testcase_26 AC 71 ms
71,220 KB
testcase_27 AC 965 ms
89,568 KB
testcase_28 TLE -
testcase_29 AC 105 ms
77,028 KB
testcase_30 AC 594 ms
82,312 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def primes(n):
    is_p = [True for i in range(n+1)]
    i = 2
    while i * i <= n:
        if is_p[i]:
            for j in range(2*i,n+1,i):
                is_p[j] = False
        i += 1
    return [i for i in range(2,n+1) if is_p[i]]

n = int(input())
p = primes(n)
ans = -1
mp = {0:0}
for i in range(len(p)):
    tmp = {}
    for x in mp:
        if x + p[i] <= n:
            tmp[x+p[i]] = max(mp[x]+1,mp[x+p[i]] if x+p[i] in mp else -1)
    mp.update(tmp)
print(mp[n] if n in mp else -1)
0