結果

問題 No.458 異なる素数の和
ユーザー h_nosonh_noson
提出日時 2017-01-26 12:57:32
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 487 bytes
コンパイル時間 491 ms
コンパイル使用メモリ 87,140 KB
実行使用メモリ 121,172 KB
最終ジャッジ日時 2023-08-24 23:55:25
合計ジャッジ時間 18,043 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
76,140 KB
testcase_01 AC 752 ms
87,028 KB
testcase_02 AC 974 ms
92,544 KB
testcase_03 AC 222 ms
77,980 KB
testcase_04 AC 272 ms
78,400 KB
testcase_05 TLE -
testcase_06 AC 922 ms
90,968 KB
testcase_07 AC 86 ms
76,096 KB
testcase_08 TLE -
testcase_09 AC 130 ms
77,164 KB
testcase_10 AC 76 ms
71,232 KB
testcase_11 TLE -
testcase_12 AC 74 ms
71,476 KB
testcase_13 AC 72 ms
71,376 KB
testcase_14 AC 74 ms
71,500 KB
testcase_15 AC 73 ms
71,384 KB
testcase_16 AC 165 ms
77,424 KB
testcase_17 AC 76 ms
71,176 KB
testcase_18 AC 77 ms
71,148 KB
testcase_19 AC 75 ms
71,180 KB
testcase_20 AC 75 ms
71,280 KB
testcase_21 AC 73 ms
71,460 KB
testcase_22 AC 73 ms
71,144 KB
testcase_23 AC 74 ms
71,220 KB
testcase_24 AC 74 ms
71,488 KB
testcase_25 AC 75 ms
71,184 KB
testcase_26 AC 76 ms
71,156 KB
testcase_27 AC 878 ms
89,792 KB
testcase_28 TLE -
testcase_29 AC 107 ms
76,904 KB
testcase_30 AC 567 ms
82,744 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(i*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)
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