結果

問題 No.458 異なる素数の和
ユーザー soyamashsoyamash
提出日時 2023-12-15 23:39:50
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 841 bytes
コンパイル時間 203 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 700,480 KB
最終ジャッジ日時 2023-12-15 23:40:02
合計ジャッジ時間 10,343 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
62,016 KB
testcase_01 AC 463 ms
262,700 KB
testcase_02 AC 606 ms
330,668 KB
testcase_03 AC 136 ms
106,156 KB
testcase_04 AC 171 ms
128,556 KB
testcase_05 MLE -
testcase_06 AC 537 ms
308,012 KB
testcase_07 AC 51 ms
66,444 KB
testcase_08 MLE -
testcase_09 AC 79 ms
82,300 KB
testcase_10 RE -
testcase_11 MLE -
testcase_12 AC 40 ms
53,588 KB
testcase_13 AC 34 ms
53,588 KB
testcase_14 AC 33 ms
53,588 KB
testcase_15 AC 33 ms
53,588 KB
testcase_16 AC 97 ms
88,364 KB
testcase_17 AC 38 ms
59,792 KB
testcase_18 AC 39 ms
59,920 KB
testcase_19 AC 39 ms
53,588 KB
testcase_20 AC 39 ms
59,920 KB
testcase_21 AC 33 ms
53,588 KB
testcase_22 AC 33 ms
53,588 KB
testcase_23 AC 39 ms
59,920 KB
testcase_24 AC 40 ms
59,920 KB
testcase_25 AC 34 ms
53,588 KB
testcase_26 AC 38 ms
59,792 KB
testcase_27 AC 545 ms
308,652 KB
testcase_28 MLE -
testcase_29 AC 61 ms
72,860 KB
testcase_30 AC 363 ms
217,900 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# https://yukicoder.me/problems/931
import math
N = int(input())


def generate_prime(X):
    max_cand = math.ceil(math.sqrt(X))
    cand_list = range(2, X + 1)
    prime_list = []
    while True:
        prime = cand_list[0]
        prime_list.append(prime)
        cand_list = [i for i in cand_list if i % prime != 0]

        if prime > max_cand:
            prime_list.extend(cand_list)
            break
    return prime_list

prime_list = generate_prime(N)
dp = [[-1 for i in range(N + 1)] for j in range(len(prime_list) + 1)]
dp[0][0] = 0
for i in range(len(prime_list)):
    flag = 0
    dp[i + 1] = dp[i][:]
    for j in range(0, N + 1):
        if dp[i][j] != -1 and j + prime_list[i] <= N:
            dp[i + 1][j + prime_list[i]
                      ] = max(dp[i][j + prime_list[i]], dp[i][j] + 1)

print(dp[-1][N])
# print(dp)
0