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 N; static int[] Prime; static bool[] isPrime; const int Max = 20000; static void Main() { Scanner sc = new Scanner(); N = sc.NextInt(); PrimeCalc(); int[] dp = (new int[Max + 1]).Select(s => -1).ToArray(); dp[0] = 0; foreach(int i in Prime) { for(int j = Max-i; j >=0; j--) { if (dp[j] != -1) { if (dp[j + i] < dp[j]+1) { dp[j + i] = dp[j] + 1; } } } } Console.WriteLine(dp[N]); } static void PrimeCalc() { int loop = (int)Math.Sqrt(Max); bool[] num = new bool[Max + 1]; num[0] = num[1] = true; for(int i = 4; i <= Max; i += 2) { num[i] = true; } for(int i = 3; i <= loop; i += 2) { if (!num[i]) { for (int j = i * 2; j <= Max; j += i) { num[j] = true; } } } List res = new List(); res.Add(2); for(int i = 3; i <= Max; i += 2) { if (!num[i]) { res.Add(i); } } Prime = res.ToArray(); isPrime = num; } } public class Scanner { private string[] S; private int Index; private char Separator; public Scanner(char separator=' ') { Index = 0; Separator = separator; } public string NextString() { string result; if (S == null) { NextLine(); } else if (Index >= S.Length) { NextLine(); } result = S[Index]; Index++; return result; } private void NextLine() { S = Console.ReadLine().Split(Separator); Index = 0; } public int NextInt() { return int.Parse(NextString()); } public double NextDouble() { return double.Parse(NextString()); } public long NextLong() { return long.Parse(NextString()); } }