using System; using System.Linq; using System.Collections.Generic; using System.Text.RegularExpressions; using System.Text; public class Program { public void Proc() { Reader.IsDebug = false; this.Num = int.Parse(Reader.ReadLine()); this.InitPrimeList(this.Num); this.memo = new Nullable[this.PrimeList.Length, this.Num+1]; int ans = this.GetAns(0, this.Num); Console.WriteLine(ans); } private Nullable[,] memo; private int GetAns(int idx, int remain) { if(idx >= this.PrimeList.Length) { if(remain == 0) { return 0; } else { return -1; } } if(remain == 0) { return 0; } if(remain < 2) { return -1; } if(this.memo[idx, remain] != null) { return this.memo[idx, remain].Value; } int ans = -1; if(PrimeList[idx] <= remain) { int ret = this.GetAns(idx+1, remain-PrimeList[idx]); if(ret >= 0) { ret++; ans = Math.Max(ans, ret); } ret = this.GetAns(idx+1, remain); if(ret >= 0) { ans = Math.Max(ans, ret); } } else { int ret = this.GetAns(idx+1, remain); if(ret >= 0) { ans = Math.Max(ans, ret); } } this.memo[idx, remain] = ans; return ans; } private int[] PrimeList; private void InitPrimeList(int num) { bool[] flags = new bool[num+1]; List list = new List(); for(int i=2; i<=num; i++) { if(flags[i]) { continue; } list.Add(i); for(int j=1; j*i<=num; j++) { flags[i*j] = true; } } list.Reverse(); this.PrimeList = list.ToArray(); } private int Num; public class Reader { public static bool IsDebug = true; private static System.IO.StringReader SReader; private static string InitText = @" 20000 "; public static string ReadLine() { if(IsDebug) { if(SReader == null) { SReader = new System.IO.StringReader(InitText.Trim()); } return SReader.ReadLine(); } else { return Console.ReadLine(); } } } public static void Main(string[] args) { Program prg = new Program(); prg.Proc(); } }