def primes2(limit): ''' returns a list of prime numbers upto limit. source: Rossetta code: Sieve of Eratosthenes http://rosettacode.org/wiki/Sieve_of_Eratosthenes#Odds-only_version_of_the_array_sieve_above ''' if limit < 2: return [] if limit < 3: return [2] lmtbf = (limit - 3) // 2 buf = [True] * (lmtbf + 1) for i in range((int(limit ** 0.5) - 3) // 2 + 1): if buf[i]: p = i + i + 3 s = p * (i + 1) + i buf[s::p] = [False] * ((lmtbf - s) // p + 1) return [2] + [i + i + 3 for i, v in enumerate(buf) if v] def solve(N): primes = primes2(N) dp = [-1] * (N + 1) dp[0] = 0 for p in primes: for i in range(N, p - 1, -1): if dp[i - p] != -1: dp[i] = max(dp[i], dp[i - p] + 1) return dp[N] N = int(input()) print(solve(N))