結果

問題 No.458 異なる素数の和
ユーザー terrafarmterrafarm
提出日時 2020-12-14 06:21:34
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,160 bytes
コンパイル時間 232 ms
コンパイル使用メモリ 12,024 KB
実行使用メモリ 16,880 KB
最終ジャッジ日時 2023-10-20 04:42:23
合計ジャッジ時間 8,764 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 56 ms
12,092 KB
testcase_01 WA -
testcase_02 TLE -
testcase_03 WA -
testcase_04 AC 493 ms
12,408 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 #

import logging
import sys
from inspect import currentframe

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline

logging.basicConfig(level=logging.DEBUG)


def sieve_eratosthenes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, n + 1):
        for j in range(2 * i, n + 1, i):
            is_prime[j] = False
    return is_prime


def dbg(*args):
    id2names = {id(v): k for k, v in currentframe().f_back.f_locals.items()}
    logging.debug(
        ", ".join(id2names.get(id(arg), "???") + " = " + repr(arg) for arg in args)
    )


def main():

    # 素数iを足す遷移を後ろからiより大きい数字に対して行う
    n = int(input())
    table = sieve_eratosthenes(n)
    dp = [-1] * (n + 1)
    dp[0] = 0
    for i, fl in enumerate(table):
        if fl:
            dp[i] = 1
    for i, fl in enumerate(table):
        if fl:
            for j in range(n, i, -1):
                if dp[j] >= 1 and j + i <= n:
                    dp[i + j] = max(dp[i + j], dp[j] + 1)
    # ans = max(dp)
    dbg(table)
    dbg(dp)
    ans = dp[n]
    print(ans)


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