結果

問題 No.458 異なる素数の和
ユーザー ch1channnch1channn
提出日時 2023-03-18 18:27:34
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 230 ms / 2,000 ms
コード長 1,004 bytes
コンパイル時間 173 ms
コンパイル使用メモリ 81,596 KB
実行使用メモリ 66,356 KB
最終ジャッジ日時 2023-10-18 17:26:57
合計ジャッジ時間 4,116 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
63,648 KB
testcase_01 AC 102 ms
66,040 KB
testcase_02 AC 119 ms
66,040 KB
testcase_03 AC 64 ms
66,040 KB
testcase_04 AC 68 ms
66,040 KB
testcase_05 AC 203 ms
66,324 KB
testcase_06 AC 115 ms
66,040 KB
testcase_07 AC 49 ms
63,648 KB
testcase_08 AC 200 ms
66,328 KB
testcase_09 AC 55 ms
63,980 KB
testcase_10 AC 44 ms
61,256 KB
testcase_11 AC 229 ms
66,356 KB
testcase_12 AC 45 ms
61,256 KB
testcase_13 AC 48 ms
61,256 KB
testcase_14 AC 48 ms
61,256 KB
testcase_15 AC 46 ms
61,256 KB
testcase_16 AC 60 ms
66,040 KB
testcase_17 AC 46 ms
61,256 KB
testcase_18 AC 45 ms
61,256 KB
testcase_19 AC 45 ms
61,256 KB
testcase_20 AC 47 ms
61,460 KB
testcase_21 AC 45 ms
61,256 KB
testcase_22 AC 45 ms
61,256 KB
testcase_23 AC 47 ms
61,460 KB
testcase_24 AC 47 ms
61,460 KB
testcase_25 AC 45 ms
61,256 KB
testcase_26 AC 45 ms
61,256 KB
testcase_27 AC 112 ms
66,040 KB
testcase_28 AC 230 ms
66,352 KB
testcase_29 AC 58 ms
63,980 KB
testcase_30 AC 92 ms
66,040 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
if sys.platform =='ios':
	import clipboard
	a=clipboard.get()
	a = a.split('\n')
	text = '\n'.join(a)
	with open('input_file.txt','w') as f:
		f.write(text)
	sys.stdin = open('input_file.txt')
sys.setrecursionlimit(410000000)
stdin = sys.stdin 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().strip()
nm = lambda: map(int,input().split())
na_1 = lambda: list(map(lambda x:int(x)*(-1), stdin.readline().split()))
na_2 = lambda: list(map(lambda x:int(x)-1, stdin.readline().split()))

N = 200000
isprime = [True] * N
isprime[0] = isprime[1] = False
for i in range(2, int(N ** 0.5 + 1)):
    if not isprime[i]:
        continue
    for j in range(i * i, N, i):
        isprime[j] = False

n = int(input())
dp = [-1 << 30] * (n + 1)
dp[0] = 0
primes = [i for i, tf in enumerate(isprime[:n + 1]) if tf]
for p in primes:
    for i in range(n, p - 1, -1):
        dp[i] = max(dp[i], dp[i - p] + 1)
if dp[n] < 0:
    dp[n] = -1
print(dp[n])

0