結果

問題 No.458 異なる素数の和
ユーザー ヒッキープログラミングするスレ GitHub ガチヒッキープログラミングするスレ GitHub ガチ
提出日時 2016-12-09 04:38:18
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 278 ms / 2,000 ms
コード長 448 bytes
コンパイル時間 1,340 ms
コンパイル使用メモリ 86,852 KB
実行使用メモリ 76,796 KB
最終ジャッジ日時 2023-09-18 14:59:14
合計ジャッジ時間 5,980 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
75,848 KB
testcase_01 AC 146 ms
76,520 KB
testcase_02 AC 163 ms
76,796 KB
testcase_03 AC 101 ms
76,684 KB
testcase_04 AC 104 ms
76,764 KB
testcase_05 AC 249 ms
76,580 KB
testcase_06 AC 156 ms
76,556 KB
testcase_07 AC 81 ms
75,976 KB
testcase_08 AC 248 ms
76,612 KB
testcase_09 AC 89 ms
76,512 KB
testcase_10 AC 73 ms
71,600 KB
testcase_11 AC 278 ms
76,784 KB
testcase_12 AC 74 ms
71,340 KB
testcase_13 AC 73 ms
71,404 KB
testcase_14 AC 75 ms
71,448 KB
testcase_15 AC 74 ms
71,524 KB
testcase_16 AC 94 ms
76,520 KB
testcase_17 AC 76 ms
71,444 KB
testcase_18 AC 74 ms
71,188 KB
testcase_19 AC 72 ms
71,360 KB
testcase_20 AC 77 ms
75,776 KB
testcase_21 AC 73 ms
71,420 KB
testcase_22 AC 74 ms
71,444 KB
testcase_23 AC 76 ms
75,640 KB
testcase_24 AC 77 ms
75,736 KB
testcase_25 AC 73 ms
71,404 KB
testcase_26 AC 75 ms
71,524 KB
testcase_27 AC 153 ms
76,468 KB
testcase_28 AC 274 ms
76,604 KB
testcase_29 AC 87 ms
76,056 KB
testcase_30 AC 130 ms
76,520 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())

s = [0] * 20001

cn = [False] * 20001

s[2] = 1

for i in range(3, n + 1, 2):
    if cn[i]:
        continue
    else:
        for j in range(i * 3, n + 1, i * 2):
            cn[j] = True
        for k in range(n - i, 1, -1):
            if s[k] == 0:
                continue
            elif s[k] + 1 > s[k + i]:
                s[k + i] = s[k] + 1
        s[i] = max(1, s[i])

if s[n] == 0:
    print(-1)
else:
    print(s[n])
0