結果

問題 No.458 異なる素数の和
ユーザー ntudantuda
提出日時 2024-01-02 17:40:36
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 719 bytes
コンパイル時間 224 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 78,472 KB
最終ジャッジ日時 2024-01-02 17:40:45
合計ジャッジ時間 8,447 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
59,968 KB
testcase_01 AC 327 ms
71,080 KB
testcase_02 AC 434 ms
71,192 KB
testcase_03 AC 109 ms
66,508 KB
testcase_04 AC 128 ms
66,508 KB
testcase_05 AC 903 ms
78,056 KB
testcase_06 AC 385 ms
71,192 KB
testcase_07 AC 45 ms
62,376 KB
testcase_08 AC 897 ms
78,060 KB
testcase_09 AC 72 ms
64,452 KB
testcase_10 RE -
testcase_11 AC 1,059 ms
78,472 KB
testcase_12 AC 35 ms
53,716 KB
testcase_13 AC 35 ms
53,716 KB
testcase_14 AC 34 ms
53,716 KB
testcase_15 AC 35 ms
53,716 KB
testcase_16 AC 83 ms
66,528 KB
testcase_17 AC 35 ms
53,716 KB
testcase_18 AC 36 ms
53,716 KB
testcase_19 AC 34 ms
53,716 KB
testcase_20 AC 38 ms
59,860 KB
testcase_21 AC 35 ms
53,716 KB
testcase_22 AC 36 ms
53,716 KB
testcase_23 AC 39 ms
59,984 KB
testcase_24 AC 41 ms
59,860 KB
testcase_25 AC 34 ms
53,716 KB
testcase_26 AC 35 ms
53,716 KB
testcase_27 AC 378 ms
71,256 KB
testcase_28 AC 1,009 ms
78,212 KB
testcase_29 AC 56 ms
64,460 KB
testcase_30 AC 240 ms
68,812 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def seachPrimeNum(N):
    max = int(N ** 0.5)
    seachList = [i for i in range(2, N + 1)]
    primeNum = []
    while seachList[0] <= max:
        primeNum.append(seachList[0])
        tmp = seachList[0]
        seachList = [i for i in seachList if i % tmp != 0]
    primeNum.extend(seachList)
    return primeNum


N = int(input())
PL = seachPrimeNum(N)
X = [0] * (N+1)
dic = {}
dic[0] = 0
for p in PL:
    dic2 = {}
    for k, v in dic.items():
        if k + p > N:
            continue
        if k + p in dic:
            if dic[k + p] < dic[k] + 1:
                dic2[k + p] = dic[k] + 1
        else:
            dic2[k + p] = dic[k] + 1
    dic.update(dic2)
if N in dic:
    print(dic[N])
else:
    print(-1)
0