結果

問題 No.458 異なる素数の和
ユーザー tcltktcltk
提出日時 2021-01-19 07:40:57
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 985 ms / 2,000 ms
コード長 1,062 bytes
コンパイル時間 361 ms
コンパイル使用メモリ 87,120 KB
実行使用メモリ 86,884 KB
最終ジャッジ日時 2023-08-22 03:39:18
合計ジャッジ時間 14,635 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 247 ms
83,832 KB
testcase_01 AC 464 ms
86,316 KB
testcase_02 AC 529 ms
86,236 KB
testcase_03 AC 305 ms
86,192 KB
testcase_04 AC 313 ms
86,680 KB
testcase_05 AC 863 ms
86,884 KB
testcase_06 AC 512 ms
86,400 KB
testcase_07 AC 252 ms
83,832 KB
testcase_08 AC 873 ms
86,824 KB
testcase_09 AC 283 ms
86,068 KB
testcase_10 AC 241 ms
83,300 KB
testcase_11 AC 985 ms
86,748 KB
testcase_12 AC 245 ms
83,492 KB
testcase_13 AC 242 ms
83,076 KB
testcase_14 AC 241 ms
83,244 KB
testcase_15 AC 240 ms
83,256 KB
testcase_16 AC 282 ms
86,284 KB
testcase_17 AC 240 ms
83,736 KB
testcase_18 AC 240 ms
83,432 KB
testcase_19 AC 242 ms
83,220 KB
testcase_20 AC 242 ms
83,832 KB
testcase_21 AC 239 ms
83,428 KB
testcase_22 AC 238 ms
83,228 KB
testcase_23 AC 242 ms
83,708 KB
testcase_24 AC 241 ms
83,660 KB
testcase_25 AC 238 ms
83,292 KB
testcase_26 AC 241 ms
83,908 KB
testcase_27 AC 499 ms
86,236 KB
testcase_28 AC 973 ms
86,832 KB
testcase_29 AC 265 ms
86,396 KB
testcase_30 AC 409 ms
86,488 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#region Header
#!/usr/bin/env python3
# from typing import *

import sys
import io
import math
import collections
import decimal
import itertools
from queue import PriorityQueue
import bisect
import heapq

def input():
    return sys.stdin.readline()[:-1]

sys.setrecursionlimit(1000000)
#endregion

# _INPUT = """3344
# """
# sys.stdin = io.StringIO(_INPUT)

def get_primes(N):
    a = [True] * (N + 1)
    l = []
    for n in range(2, N + 1):
        if a[n]:
            l.append(n)
            for i in range(n+n, N + 1, n):
                a[i] = False
    return l

def main():
    N = int(input())
    primes = get_primes(N)

    T = [0 for _ in range(N+1)]
    for p in primes:
        T[p] = max(T[p], 1)
        for i in reversed(range(2, N+1)):
            if i == p and T[i] == 1:
                continue
            if T[i] > 0 and i+p <= N:
                T[i+p] = max(T[i+p], T[i] + 1)

    if T[N] > 0:
        print(T[N])
    else:
        print(-1)

if __name__ == '__main__':
    main()
0