結果

問題 No.458 異なる素数の和
ユーザー h_nosonh_noson
提出日時 2017-01-26 12:44:17
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 496 bytes
コンパイル時間 308 ms
コンパイル使用メモリ 86,840 KB
実行使用メモリ 121,464 KB
最終ジャッジ日時 2023-08-24 23:55:05
合計ジャッジ時間 16,673 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
76,232 KB
testcase_01 AC 743 ms
87,400 KB
testcase_02 AC 914 ms
92,592 KB
testcase_03 AC 203 ms
78,084 KB
testcase_04 AC 244 ms
78,508 KB
testcase_05 TLE -
testcase_06 AC 864 ms
91,044 KB
testcase_07 AC 81 ms
76,368 KB
testcase_08 TLE -
testcase_09 AC 118 ms
77,280 KB
testcase_10 AC 69 ms
71,316 KB
testcase_11 TLE -
testcase_12 AC 70 ms
71,396 KB
testcase_13 AC 68 ms
71,340 KB
testcase_14 AC 70 ms
71,232 KB
testcase_15 AC 69 ms
71,228 KB
testcase_16 AC 155 ms
77,420 KB
testcase_17 AC 72 ms
71,396 KB
testcase_18 AC 70 ms
71,312 KB
testcase_19 AC 71 ms
71,144 KB
testcase_20 AC 72 ms
71,124 KB
testcase_21 AC 70 ms
71,452 KB
testcase_22 AC 70 ms
71,056 KB
testcase_23 AC 70 ms
71,048 KB
testcase_24 AC 70 ms
71,140 KB
testcase_25 AC 69 ms
71,276 KB
testcase_26 AC 68 ms
71,180 KB
testcase_27 AC 813 ms
89,788 KB
testcase_28 TLE -
testcase_29 AC 101 ms
77,060 KB
testcase_30 AC 517 ms
82,944 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: break
        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