def make_prime_numbers(n): ''' n以下の素数を列挙したリストを出力する 計算量:O(NloglogN) 入出力例:30 -> [2, 3, 5, 7, 11, 13, 17, 19, 23, 29] ''' is_prime = [True]*(n+1) is_prime[0] = False is_prime[1] = False for i in range(2, int(n**0.5) + 1): if not is_prime[i]: continue for j in range(2 * i, n + 1, i): is_prime[j] = False prime_numbers = [i for i in range(n + 1) if is_prime[i]] return prime_numbers n = int(input()) prime_list = make_prime_numbers(n) # dp[i][j] := i個めまでの素数を選んだときに値がjになるとき選んだ個数の最大値 dp = [[-1]*(n+1) for i in range(len(prime_list) + 1)] for i in range(len(prime_list)): dp[i][0] = 0 for i in range(len(prime_list)): for j in range(n+1): if prime_list[i] > j: dp[i+1][j] = dp[i][j] else: if dp[i][j-prime_list[i]] == -1: dp[i+1][j] = max(dp[i][j], -1) else: dp[i+1][j] = max(dp[i][j], dp[i][j-prime_list[i]] + 1) print(dp[len(prime_list)][n])