結果
問題 | No.458 異なる素数の和 |
ユーザー |
![]() |
提出日時 | 2020-04-06 21:08:19 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 270 ms / 2,000 ms |
コード長 | 1,187 bytes |
コンパイル時間 | 257 ms |
コンパイル使用メモリ | 82,088 KB |
実行使用メモリ | 67,372 KB |
最終ジャッジ日時 | 2024-07-07 01:31:03 |
合計ジャッジ時間 | 3,759 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 28 |
ソースコード
''' https://yukicoder.me/problems/931 ''' def main(): import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) from collections import Counter, deque #from collections import defaultdict from itertools import combinations, permutations, accumulate, groupby #from itertools import product from bisect import bisect_left,bisect_right from heapq import heapify, heappop, heappush from math import floor, ceil #from operator import itemgetter #inf = 10**17 #mod = 10**9 + 7 n = int(input()) def primecheck(n): #0~nまで素数判定 p = [True] * (n + 1) p[0] = False p[1] = False for i in range(2, int(n ** 0.5) + 1): if p[i]: for j in range(i * i, n + 1, i): p[j] = False return p p = primecheck(n) l = [] for i, x in enumerate(p): if x: l.append(i) dp = [-1]*(n+1) dp[0] = 0 for i in l: for j in range(n, i-1, -1): if dp[j-i] >= 0: dp[j] = max(dp[j-i]+1, dp[j]) print(dp[-1]) if __name__ == '__main__': main()