結果

問題 No.458 異なる素数の和
ユーザー _matumo__matumo_
提出日時 2019-05-13 14:48:32
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 518 bytes
コンパイル時間 395 ms
コンパイル使用メモリ 87,044 KB
実行使用メモリ 79,316 KB
最終ジャッジ日時 2023-09-21 22:12:10
合計ジャッジ時間 7,735 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
75,856 KB
testcase_01 AC 258 ms
76,768 KB
testcase_02 AC 307 ms
76,832 KB
testcase_03 AC 122 ms
76,832 KB
testcase_04 AC 134 ms
76,440 KB
testcase_05 AC 582 ms
76,884 KB
testcase_06 AC 293 ms
76,500 KB
testcase_07 AC 84 ms
76,304 KB
testcase_08 AC 593 ms
77,112 KB
testcase_09 AC 96 ms
76,920 KB
testcase_10 AC 72 ms
71,212 KB
testcase_11 AC 683 ms
77,108 KB
testcase_12 AC 73 ms
71,376 KB
testcase_13 AC 72 ms
71,132 KB
testcase_14 AC 73 ms
71,508 KB
testcase_15 RE -
testcase_16 AC 106 ms
76,652 KB
testcase_17 AC 76 ms
75,392 KB
testcase_18 AC 76 ms
75,680 KB
testcase_19 AC 71 ms
71,656 KB
testcase_20 AC 79 ms
75,900 KB
testcase_21 AC 72 ms
71,532 KB
testcase_22 AC 73 ms
71,620 KB
testcase_23 AC 78 ms
76,008 KB
testcase_24 AC 83 ms
75,996 KB
testcase_25 AC 79 ms
71,756 KB
testcase_26 AC 77 ms
75,780 KB
testcase_27 AC 285 ms
76,600 KB
testcase_28 AC 676 ms
77,212 KB
testcase_29 AC 88 ms
76,612 KB
testcase_30 AC 206 ms
76,856 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def prmCn(N):
    if N < 2:
        return -1
    if N < 4:
        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