結果

問題 No.458 異なる素数の和
ユーザー hokekiyoohokekiyoo
提出日時 2020-02-18 23:05:16
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 967 bytes
コンパイル時間 247 ms
コンパイル使用メモリ 82,328 KB
実行使用メモリ 689,624 KB
最終ジャッジ日時 2024-04-16 04:19:28
合計ジャッジ時間 11,098 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 63 ms
64,896 KB
testcase_01 AC 491 ms
269,696 KB
testcase_02 AC 575 ms
296,968 KB
testcase_03 AC 163 ms
114,968 KB
testcase_04 AC 188 ms
130,304 KB
testcase_05 MLE -
testcase_06 AC 559 ms
304,744 KB
testcase_07 AC 64 ms
66,560 KB
testcase_08 MLE -
testcase_09 AC 94 ms
82,948 KB
testcase_10 AC 54 ms
60,400 KB
testcase_11 MLE -
testcase_12 AC 52 ms
61,008 KB
testcase_13 WA -
testcase_14 AC 49 ms
61,008 KB
testcase_15 AC 50 ms
61,224 KB
testcase_16 AC 115 ms
98,964 KB
testcase_17 AC 51 ms
61,600 KB
testcase_18 AC 53 ms
62,284 KB
testcase_19 AC 50 ms
60,224 KB
testcase_20 AC 55 ms
64,808 KB
testcase_21 AC 50 ms
60,284 KB
testcase_22 AC 49 ms
60,752 KB
testcase_23 AC 54 ms
64,052 KB
testcase_24 AC 54 ms
62,308 KB
testcase_25 AC 49 ms
61,024 KB
testcase_26 AC 52 ms
61,824 KB
testcase_27 AC 513 ms
302,000 KB
testcase_28 MLE -
testcase_29 AC 70 ms
75,104 KB
testcase_30 AC 343 ms
221,072 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

"""
Nをそれぞれ異なる素数の和で表すことができる場合,
その中での最大の和の回数Mを出力してください。


dp[i] : iを異なる素数の和で表せるmax
"""
N = int(input())
INF = 10**10
U = 10**5
# is_prime = np.zeros(U,np.bool) #素数列挙(エラトステネス)
is_prime = [0] * U
is_prime[2] = 1
for i in range(3,U,2):
    is_prime[i] = 1
for p in range(3,U,2):
    if p*p > U:
        break
    if is_prime[p]:
        for i in range(p*p,U,p+p):
            is_prime[i] = 0
primes = [i for i,p in enumerate(is_prime) if p and i < N]
dp = [[-INF] * (N+1) for i in range(len(primes)+1)]
dp[0][0] = 0

# print("len",len(primes))
for i in range(len(primes)):
    p = primes[i]
    dp[i+1][:] = dp[i][:]
    for j in range(N):
        if dp[i][j] == -INF : continue
        if j + p <= N:
            dp[i+1][j+p] = max(dp[i][j+p], dp[i][j] + 1)
ans = dp[len(primes)][N]
if ans == -INF:
    print(-1)
else:
    print(ans)
0