using System; using System.Collections.Generic; using System.Text; using System.Linq; class Program { public void Proc() { Reader.IsDebug = true; long num = long.Parse(Reader.ReadLine()); long max = num-1; long min = num; if (num == 1) { min = 0; } else if(min == 2) { min = 1; } else { this.soinsuList = this.SoinsuBunkai(num); this.dic = new Dictionary>[(1< soinsuList; Dictionary>[] dic; private long GetAns(int target, long added, int remain) { if(dic[target] == null) { dic[target] = new Dictionary>(); } if(!dic[target].ContainsKey(added)) { dic[target].Add(added, new Dictionary()); } if(dic[target][added].ContainsKey(remain)) { return dic[target][added][remain]; } long ans = -1; if(remain == 0) { ans = 1; for(int i=0; i 0) { tmpAns = Math.Min(tmpAns, ret); } ret = this.GetAns(target + key, 1, remain - 1); if(ret > 0) { tmpAns = Math.Min(tmpAns, ret + (added * this.soinsuList[i] - 1)); } } } if(tmpAns != long.MaxValue) { ans = tmpAns; } } dic[target][added].Add(remain, ans); return ans; } private List SoinsuBunkai(long target) { List ret = new List(); long num = target; for (long i =2; i<=Math.Sqrt(target); i++) { if(i > num) { break; } while (num % i == 0) { ret.Add(i); num = num / i; } } if(num > 1) { ret.Add(num); } return ret; } public class Reader { public static bool IsDebug = true; private static String PlainInput = @" 4163034477 "; private static System.IO.StringReader Sr = null; public static string ReadLine() { if (IsDebug) { if (Sr == null) { Sr = new System.IO.StringReader(PlainInput.Trim()); } return Sr.ReadLine(); } else { return Console.ReadLine(); } } } static void Main() { Program prg = new Program(); prg.Proc(); } }