結果
問題 |
No.458 異なる素数の和
|
ユーザー |
|
提出日時 | 2017-03-18 03:06:49 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
TLE
|
実行時間 | - |
コード長 | 668 bytes |
コンパイル時間 | 206 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 18,456 KB |
最終ジャッジ日時 | 2024-07-04 14:01:51 |
合計ジャッジ時間 | 9,962 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | -- * 3 |
other | AC * 3 TLE * 3 -- * 22 |
ソースコード
from sys import stdin, stdout, stderr def solve(): N = int(input()) ps = make_primes(N + 1) minf = -(len(ps) + 1) dp = [minf] * (N + 1) dp[0] = 0 for p in ps: for i in range(N, p - 1, -1): dp[i] = max(dp[i], dp[i - p] + 1) # print(dp) ans = dp[N] if ans > 0: print(ans) else: print(-1) def make_primes(N): sieve = [True] * N sieve[0] = sieve[1] = False for p in range(2, N): if not sieve[p]: continue for m in range(p**2, N, p): sieve[m] = False return [i for i in range(N) if sieve[i]] if __name__ == '__main__': solve()