結果

問題 No.458 異なる素数の和
ユーザー ntudantuda
提出日時 2024-01-02 17:50:13
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,279 ms / 2,000 ms
コード長 633 bytes
コンパイル時間 300 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 152,700 KB
最終ジャッジ日時 2024-01-02 17:50:23
合計ジャッジ時間 9,722 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
62,244 KB
testcase_01 AC 374 ms
76,900 KB
testcase_02 AC 509 ms
77,516 KB
testcase_03 AC 127 ms
75,728 KB
testcase_04 AC 149 ms
75,728 KB
testcase_05 AC 1,111 ms
145,248 KB
testcase_06 AC 466 ms
77,516 KB
testcase_07 AC 48 ms
64,324 KB
testcase_08 AC 1,077 ms
145,252 KB
testcase_09 AC 78 ms
75,600 KB
testcase_10 AC 34 ms
53,460 KB
testcase_11 AC 1,279 ms
150,400 KB
testcase_12 AC 35 ms
53,716 KB
testcase_13 AC 35 ms
53,716 KB
testcase_14 AC 36 ms
53,716 KB
testcase_15 AC 36 ms
53,716 KB
testcase_16 AC 103 ms
75,728 KB
testcase_17 AC 36 ms
53,716 KB
testcase_18 AC 35 ms
53,716 KB
testcase_19 AC 35 ms
53,716 KB
testcase_20 AC 41 ms
59,988 KB
testcase_21 AC 35 ms
53,716 KB
testcase_22 AC 35 ms
53,716 KB
testcase_23 AC 39 ms
59,736 KB
testcase_24 AC 40 ms
59,736 KB
testcase_25 AC 36 ms
53,716 KB
testcase_26 AC 36 ms
53,716 KB
testcase_27 AC 468 ms
77,404 KB
testcase_28 AC 1,249 ms
152,700 KB
testcase_29 AC 65 ms
73,168 KB
testcase_30 AC 313 ms
76,512 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)
Q = {0}
for p in PL:
    for q in sorted(list(Q),reverse = True):
        if p + q > N:
            continue
        X[p + q] = max(X[p + q], X[q] + 1)
        Q.add(p + q)

if X[N] > 0:
    print(X[N])
else:
    print(-1)
0