結果

問題 No.458 異なる素数の和
ユーザー phtmscgphtmscg
提出日時 2019-05-13 19:12:18
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 714 ms / 2,000 ms
コード長 366 bytes
コンパイル時間 1,065 ms
コンパイル使用メモリ 86,612 KB
実行使用メモリ 76,648 KB
最終ジャッジ日時 2023-09-22 08:20:27
合計ジャッジ時間 7,429 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
75,548 KB
testcase_01 AC 265 ms
76,168 KB
testcase_02 AC 316 ms
76,264 KB
testcase_03 AC 118 ms
76,028 KB
testcase_04 AC 131 ms
75,780 KB
testcase_05 AC 610 ms
76,180 KB
testcase_06 AC 302 ms
76,076 KB
testcase_07 AC 79 ms
75,804 KB
testcase_08 AC 618 ms
76,164 KB
testcase_09 AC 91 ms
76,280 KB
testcase_10 AC 68 ms
71,128 KB
testcase_11 AC 714 ms
76,648 KB
testcase_12 AC 67 ms
71,228 KB
testcase_13 AC 70 ms
71,112 KB
testcase_14 AC 67 ms
71,032 KB
testcase_15 AC 68 ms
71,036 KB
testcase_16 AC 101 ms
76,064 KB
testcase_17 AC 71 ms
75,000 KB
testcase_18 AC 71 ms
74,972 KB
testcase_19 AC 66 ms
71,124 KB
testcase_20 AC 73 ms
75,472 KB
testcase_21 AC 68 ms
71,124 KB
testcase_22 AC 67 ms
70,960 KB
testcase_23 AC 69 ms
75,364 KB
testcase_24 AC 75 ms
75,124 KB
testcase_25 AC 68 ms
71,196 KB
testcase_26 AC 70 ms
74,928 KB
testcase_27 AC 294 ms
75,892 KB
testcase_28 AC 707 ms
76,544 KB
testcase_29 AC 85 ms
76,064 KB
testcase_30 AC 210 ms
76,396 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())

def dpsum(N):
    if N == 1:
        return -1
    pn = [2]
    for i in range(3,N+1,2):
        for s in pn:
            if i%s == 0:break
        else:pn += [i]
    Q = [1]+[0]*N
    for p in pn:
        for i in range(N,-1,-1):
            if Q[i] > 0 and i+p <= N:
                Q[i+p] = max(Q[i+p], Q[i]+1)
    return Q[N]-1

print(dpsum(N))
0