結果

問題 No.458 異なる素数の和
ユーザー h_nosonh_noson
提出日時 2017-01-26 13:08:55
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 856 ms / 2,000 ms
コード長 504 bytes
コンパイル時間 287 ms
コンパイル使用メモリ 87,104 KB
実行使用メモリ 78,696 KB
最終ジャッジ日時 2023-09-18 15:17:44
合計ジャッジ時間 8,388 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
76,104 KB
testcase_01 AC 297 ms
76,832 KB
testcase_02 AC 362 ms
77,396 KB
testcase_03 AC 128 ms
76,604 KB
testcase_04 AC 141 ms
76,472 KB
testcase_05 AC 712 ms
78,264 KB
testcase_06 AC 340 ms
77,156 KB
testcase_07 AC 79 ms
76,148 KB
testcase_08 AC 712 ms
78,388 KB
testcase_09 AC 99 ms
76,676 KB
testcase_10 AC 75 ms
71,512 KB
testcase_11 AC 855 ms
78,624 KB
testcase_12 AC 74 ms
71,256 KB
testcase_13 AC 73 ms
71,272 KB
testcase_14 AC 73 ms
71,448 KB
testcase_15 AC 70 ms
71,512 KB
testcase_16 AC 111 ms
76,492 KB
testcase_17 AC 74 ms
71,036 KB
testcase_18 AC 74 ms
71,376 KB
testcase_19 AC 75 ms
71,508 KB
testcase_20 AC 78 ms
71,180 KB
testcase_21 AC 74 ms
71,380 KB
testcase_22 AC 74 ms
71,508 KB
testcase_23 AC 74 ms
71,388 KB
testcase_24 AC 73 ms
71,460 KB
testcase_25 AC 73 ms
71,036 KB
testcase_26 AC 73 ms
71,176 KB
testcase_27 AC 327 ms
77,188 KB
testcase_28 AC 843 ms
78,696 KB
testcase_29 AC 90 ms
76,448 KB
testcase_30 AC 233 ms
76,896 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
        if not x+p[i] in mp or mp[x]+1 > mp[x+p[i]]:
            tmp[x+p[i]] = mp[x]+1
    mp.update(tmp)
print(mp[n] if n in mp else -1)
0