結果

問題 No.458 異なる素数の和
ユーザー titiatitia
提出日時 2023-08-30 04:23:48
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 759 bytes
コンパイル時間 395 ms
コンパイル使用メモリ 87,252 KB
実行使用メモリ 238,124 KB
最終ジャッジ日時 2023-08-30 04:23:57
合計ジャッジ時間 9,094 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 115 ms
80,752 KB
testcase_01 RE -
testcase_02 RE -
testcase_03 AC 1,108 ms
116,720 KB
testcase_04 AC 1,063 ms
121,812 KB
testcase_05 RE -
testcase_06 RE -
testcase_07 AC 182 ms
84,612 KB
testcase_08 RE -
testcase_09 AC 297 ms
98,836 KB
testcase_10 WA -
testcase_11 RE -
testcase_12 WA -
testcase_13 AC 72 ms
71,540 KB
testcase_14 AC 72 ms
71,388 KB
testcase_15 WA -
testcase_16 AC 463 ms
105,676 KB
testcase_17 AC 73 ms
71,428 KB
testcase_18 AC 74 ms
71,388 KB
testcase_19 AC 72 ms
71,424 KB
testcase_20 AC 78 ms
75,812 KB
testcase_21 AC 74 ms
71,516 KB
testcase_22 WA -
testcase_23 AC 74 ms
71,392 KB
testcase_24 AC 76 ms
75,592 KB
testcase_25 AC 72 ms
71,392 KB
testcase_26 AC 72 ms
71,384 KB
testcase_27 RE -
testcase_28 RE -
testcase_29 WA -
testcase_30 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

N=int(input())


x=N
import math 
L=math.floor(math.sqrt(x)) # 平方根を求める

Primelist=[i for i in range(x+1)]
Primelist[1]=0 # 1は素数でないので0にする.
 
for i in Primelist:
    if i>L:
        break
    if i==0:
        continue
    for j in range(2*i,x+1,i):
        Primelist[j]=0

Primes=[Primelist[j] for j in range(x+1) if Primelist[j]!=0]
Primes.reverse()

DP=[[-1]*1000 for i in range(N+1)]


def calc(N,i):
    if DP[N][i]!=-1:
        return DP[N][i]

    if N==0:
        return 0
    if i>=len(Primes) or Primes[i]>N:
        return -1<<60
    
    ANS=0
    for j in range(i,len(Primes)):
        if N-Primes[j]>=0:
            ANS=max(ANS,calc(N-Primes[j],j+1)+1)

    DP[N][i]=ANS
    return ANS

print(calc(N,0))

    


0