using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Text; using System.Text.RegularExpressions; using System.Linq; class Magatro { static int[] Primes; static int N = int.Parse(Console.ReadLine()); static void Main() { PrimeCalc(); int[,] B = new int[20001, Primes.Length + 1]; for(int i = 0; i <= N; i++) { for(int j = 0; j <= Primes.Length;j++) { B[i, j] = -1; } } B[0, 0] = 0; for(int i = 0; i < Primes.Length; i++) { for(int j = 0; j <= N; j++) { if (B[j, i] == -1) { continue; } B[j, i + 1] =Math.Max(B[j, i], B[j, i + 1]); if (j + Primes[i] > N) { continue; } if(B[j + Primes[i], i + 1]==-1) B[j + Primes[i], i + 1] = B[j, i] + 1; else { B[j + Primes[i], i + 1] = Math.Max(B[j, i] + 1, B[j + Primes[i], i + 1]); } } } int max = -1; for(int i = 1; i <= Primes.Length; i++) { max = Math.Max(max, B[N,i]); } Console.WriteLine(max); } static void PrimeCalc() { bool[] a = new bool[N + 1]; a[0] = true; a[1] = true; for(int i = 2; i <= Math.Sqrt(N); i++) { if (!a[i]) { for(int j = i * 2; j <= N; j += i) { a[j] = true; } } } List L = new List(); for(int i = 0; i <= N; i++) { if (!a[i]) { L.Add(i); } } Primes = L.ToArray(); } } struct A { public A(int num,int cnt) { Num = num; Cnt = cnt; } public int Num; public int Cnt; }