結果

問題 No.458 異なる素数の和
ユーザー phtmscgphtmscg
提出日時 2019-04-21 01:50:35
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 657 bytes
コンパイル時間 268 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-04-14 05:56:51
合計ジャッジ時間 5,248 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,752 KB
testcase_01 AC 139 ms
10,880 KB
testcase_02 AC 197 ms
10,752 KB
testcase_03 AC 65 ms
10,752 KB
testcase_04 AC 61 ms
10,880 KB
testcase_05 AC 761 ms
11,008 KB
testcase_06 AC 242 ms
10,752 KB
testcase_07 AC 32 ms
10,752 KB
testcase_08 WA -
testcase_09 AC 42 ms
10,752 KB
testcase_10 AC 30 ms
10,880 KB
testcase_11 AC 347 ms
10,880 KB
testcase_12 AC 30 ms
10,752 KB
testcase_13 AC 31 ms
10,752 KB
testcase_14 AC 30 ms
10,880 KB
testcase_15 AC 30 ms
10,880 KB
testcase_16 AC 45 ms
10,752 KB
testcase_17 AC 31 ms
10,752 KB
testcase_18 AC 30 ms
10,752 KB
testcase_19 AC 31 ms
10,880 KB
testcase_20 WA -
testcase_21 AC 31 ms
10,752 KB
testcase_22 AC 31 ms
10,752 KB
testcase_23 AC 31 ms
10,880 KB
testcase_24 AC 30 ms
10,752 KB
testcase_25 AC 30 ms
10,752 KB
testcase_26 AC 30 ms
10,752 KB
testcase_27 AC 148 ms
10,752 KB
testcase_28 AC 338 ms
10,880 KB
testcase_29 AC 36 ms
10,752 KB
testcase_30 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
if N > 1:
    p = [2]
    for i in range(3,N+1,2):
        for s in p:
            if i%s == 0:
                break
        else:
            p += [i]
else:
    print(-1)
    exit()

p = p[::-1]
Q = [0]*len(p)
q = 0
i = len(p)-1
while True:
    if i >= 0:
        if q + p[i] == N:
            Q[i] = 1
            break
        elif q + p[i] < N:
            Q[i] = 1
            q += p[i]
            i -= 1
        elif Q.count(1) == 0:
            break
        else:
            d = Q.index(1)
            q -= p[d]
            Q[d] = 0
            i = d-1
    else:
        Q = [0]
        break
print(sum(Q) if sum(Q) != 0 else -1)
0