結果

問題 No.458 異なる素数の和
ユーザー _matumo__matumo_
提出日時 2019-05-13 14:54:01
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 683 ms / 2,000 ms
コード長 550 bytes
コンパイル時間 367 ms
コンパイル使用メモリ 86,720 KB
実行使用メモリ 76,968 KB
最終ジャッジ日時 2023-09-21 22:38:37
合計ジャッジ時間 7,722 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
75,768 KB
testcase_01 AC 259 ms
76,404 KB
testcase_02 AC 309 ms
76,664 KB
testcase_03 AC 125 ms
76,672 KB
testcase_04 AC 136 ms
76,696 KB
testcase_05 AC 583 ms
76,848 KB
testcase_06 AC 295 ms
76,636 KB
testcase_07 AC 86 ms
76,340 KB
testcase_08 AC 594 ms
76,952 KB
testcase_09 AC 97 ms
76,408 KB
testcase_10 AC 77 ms
71,384 KB
testcase_11 AC 683 ms
76,808 KB
testcase_12 AC 73 ms
71,636 KB
testcase_13 AC 72 ms
71,032 KB
testcase_14 AC 74 ms
71,480 KB
testcase_15 AC 72 ms
71,280 KB
testcase_16 AC 108 ms
76,636 KB
testcase_17 AC 79 ms
75,524 KB
testcase_18 AC 77 ms
75,564 KB
testcase_19 AC 75 ms
71,616 KB
testcase_20 AC 85 ms
75,808 KB
testcase_21 AC 75 ms
71,736 KB
testcase_22 AC 77 ms
71,628 KB
testcase_23 AC 83 ms
75,672 KB
testcase_24 AC 83 ms
75,696 KB
testcase_25 AC 79 ms
71,428 KB
testcase_26 AC 81 ms
75,472 KB
testcase_27 AC 288 ms
76,668 KB
testcase_28 AC 677 ms
76,968 KB
testcase_29 AC 89 ms
76,496 KB
testcase_30 AC 208 ms
76,824 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def prmCn(N):
    if N < 2:
        return -1
    if N < 4:
        return 1
    if N < 5:
        return -1
    pa = [i for i in range(5, N+1, 2) if i % 3]
    pr = [2, 3]
    rN = int(N**0.5)
    while True:
        m = pa[0]
        if m >= rN:
            break
        pr += [m]
        pa = [n for n in pa[1:] if n % m]
    pr += pa
    pa = [1]+[0]*N
    for r in pr:
        for j in range(N, -1, -1):
            if pa[j] > 0 and j+r <= N:
                pa[j+r] = max(pa[j+r], pa[j]+1)
    return pa[N]-1


N = int(input())
print(prmCn(N))
0