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 = [0] * (N + 1) dp[0] = 1 cumsum = 0 for p in primes: cumsum += p for i in range(min(cumsum, N), p - 1, -1): tmp = dp[i - p] if tmp and tmp + 1 > dp[i]: dp[i] = tmp + 1 return dp[N] - 1 N = int(input()) print(solve(N))