結果

問題 No.458 異なる素数の和
ユーザー noriocnorioc
提出日時 2016-12-10 16:56:10
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 751 bytes
コンパイル時間 741 ms
コンパイル使用メモリ 10,948 KB
実行使用メモリ 12,332 KB
最終ジャッジ日時 2023-08-19 09:31:53
合計ジャッジ時間 6,550 ms
ジャッジサーバーID
(参考情報)
judge11 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
12,332 KB
testcase_01 TLE -
testcase_02 TLE -
testcase_03 AC 471 ms
7,800 KB
testcase_04 AC 641 ms
8,288 KB
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

# coding: utf-8

def readint():
    return int(input())

def readints():
    return list(map(int, input().split()))

def sieve(n):
    primes = [2] if n >= 2 else []
    used = [False] * (n + 1)
    for i in range(3, n + 1, 2):
        if not used[i]:
            primes.append(i)
            for j in range(i + i, n + 1, i):
                used[j] = True
    return primes

def main():
    n = readint()

    primes = sieve(n)
    dp = [0] * (n + 1)
    for p in primes:
        for i in range(n, 0, -1):
            if i + p <= n and dp[i] > 0:
                dp[i + p] = max(dp[i + p], dp[i] + 1)
        dp[p] = max(dp[p], 1)

    ans = dp[n]
    if ans > 1:
        print(ans)
    else:
        print(-1)

if __name__ == "__main__":
    main()
0