結果

問題 No.458 異なる素数の和
ユーザー terrafarmterrafarm
提出日時 2020-12-14 06:31:44
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 743 ms / 2,000 ms
コード長 1,186 bytes
コンパイル時間 176 ms
コンパイル使用メモリ 81,864 KB
実行使用メモリ 81,860 KB
最終ジャッジ日時 2023-10-20 04:43:10
合計ジャッジ時間 8,079 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 101 ms
80,224 KB
testcase_01 AC 289 ms
80,704 KB
testcase_02 AC 344 ms
80,736 KB
testcase_03 AC 147 ms
80,724 KB
testcase_04 AC 159 ms
80,740 KB
testcase_05 AC 635 ms
81,000 KB
testcase_06 AC 330 ms
80,732 KB
testcase_07 AC 103 ms
80,560 KB
testcase_08 AC 639 ms
80,984 KB
testcase_09 AC 120 ms
80,724 KB
testcase_10 AC 93 ms
79,876 KB
testcase_11 AC 743 ms
81,860 KB
testcase_12 AC 98 ms
79,884 KB
testcase_13 AC 93 ms
79,876 KB
testcase_14 AC 94 ms
79,884 KB
testcase_15 AC 94 ms
79,880 KB
testcase_16 AC 129 ms
80,712 KB
testcase_17 AC 95 ms
80,068 KB
testcase_18 AC 100 ms
79,944 KB
testcase_19 AC 93 ms
79,880 KB
testcase_20 AC 97 ms
80,204 KB
testcase_21 AC 94 ms
79,872 KB
testcase_22 AC 95 ms
79,880 KB
testcase_23 AC 96 ms
80,208 KB
testcase_24 AC 99 ms
80,220 KB
testcase_25 AC 95 ms
79,876 KB
testcase_26 AC 95 ms
80,064 KB
testcase_27 AC 318 ms
80,736 KB
testcase_28 AC 730 ms
81,828 KB
testcase_29 AC 112 ms
80,572 KB
testcase_30 AC 236 ms
80,712 KB
権限があれば一括ダウンロードができます

ソースコード

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を足す遷移を後ろから後ろから行う
    n = int(input())
    table = sieve_eratosthenes(n)
    dp = [-1] * (n + 1)
    # for i, fl in enumerate(table):
    #     if fl:
    #         dp[i] = 1
    dp[0] = 0
    for i, fl in enumerate(table):
        if fl:
            # for j in range(n, i, -1):
            for j in range(n, -1, -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