結果

問題 No.458 異なる素数の和
ユーザー ntudantuda
提出日時 2024-01-02 17:42:15
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,045 ms / 2,000 ms
コード長 755 bytes
コンパイル時間 324 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 78,476 KB
最終ジャッジ日時 2024-01-02 17:42:24
合計ジャッジ時間 8,400 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
59,976 KB
testcase_01 AC 330 ms
71,080 KB
testcase_02 AC 436 ms
71,196 KB
testcase_03 AC 107 ms
66,512 KB
testcase_04 AC 128 ms
66,512 KB
testcase_05 AC 907 ms
78,060 KB
testcase_06 AC 381 ms
71,196 KB
testcase_07 AC 46 ms
62,380 KB
testcase_08 AC 890 ms
78,064 KB
testcase_09 AC 67 ms
64,456 KB
testcase_10 AC 35 ms
53,460 KB
testcase_11 AC 1,045 ms
78,476 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,532 KB
testcase_17 AC 36 ms
53,716 KB
testcase_18 AC 35 ms
53,716 KB
testcase_19 AC 36 ms
53,716 KB
testcase_20 AC 40 ms
59,864 KB
testcase_21 AC 35 ms
53,716 KB
testcase_22 AC 35 ms
53,716 KB
testcase_23 AC 41 ms
59,988 KB
testcase_24 AC 38 ms
59,864 KB
testcase_25 AC 35 ms
53,716 KB
testcase_26 AC 35 ms
53,716 KB
testcase_27 AC 379 ms
71,260 KB
testcase_28 AC 1,001 ms
78,088 KB
testcase_29 AC 58 ms
64,464 KB
testcase_30 AC 247 ms
68,816 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())
if N == 1:
    print(-1)
    exit()
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