結果

問題 No.458 異なる素数の和
ユーザー asumo0729asumo0729
提出日時 2020-12-16 11:15:11
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 539 ms / 2,000 ms
コード長 859 bytes
コンパイル時間 259 ms
コンパイル使用メモリ 81,848 KB
実行使用メモリ 66,652 KB
最終ジャッジ日時 2023-10-20 09:16:57
合計ジャッジ時間 7,032 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 60 ms
64,024 KB
testcase_01 AC 334 ms
66,496 KB
testcase_02 AC 370 ms
66,496 KB
testcase_03 AC 192 ms
66,496 KB
testcase_04 AC 211 ms
66,496 KB
testcase_05 AC 503 ms
66,636 KB
testcase_06 AC 359 ms
66,496 KB
testcase_07 AC 73 ms
64,024 KB
testcase_08 AC 504 ms
66,636 KB
testcase_09 AC 135 ms
66,468 KB
testcase_10 AC 42 ms
56,852 KB
testcase_11 AC 539 ms
66,652 KB
testcase_12 AC 46 ms
59,812 KB
testcase_13 AC 46 ms
59,812 KB
testcase_14 AC 46 ms
59,812 KB
testcase_15 AC 46 ms
59,812 KB
testcase_16 AC 159 ms
66,496 KB
testcase_17 AC 52 ms
61,956 KB
testcase_18 AC 55 ms
64,024 KB
testcase_19 AC 46 ms
59,812 KB
testcase_20 AC 55 ms
64,024 KB
testcase_21 AC 47 ms
59,812 KB
testcase_22 AC 46 ms
59,812 KB
testcase_23 AC 55 ms
64,024 KB
testcase_24 AC 55 ms
64,024 KB
testcase_25 AC 52 ms
61,956 KB
testcase_26 AC 53 ms
61,956 KB
testcase_27 AC 351 ms
66,496 KB
testcase_28 AC 538 ms
66,648 KB
testcase_29 AC 110 ms
66,468 KB
testcase_30 AC 292 ms
66,496 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
stdin=sys.stdin

ip=lambda: int(sp())
fp=lambda: float(sp())
lp=lambda:list(map(int,stdin.readline().split()))
sp=lambda:stdin.readline().rstrip()
yp=lambda:print('Yes')
np=lambda:print('No')

def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]

n=ip()
sosuu=primes(n)
dp=[0 for _ in range(20001)]
for i in range(len(sosuu)):
    for j in range(20000,-1,-1):
        if j==0:
            dp[j+sosuu[i]]=max(dp[j+sosuu[i]],1)
        else:
            if 0<=j-sosuu[i] and dp[j-sosuu[i]]!=0:
                dp[j]=max(dp[j],dp[j-sosuu[i]]+1)

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