using System; using System.Collections.Generic; using System.Text; using System.Linq; class Program { public void Proc() { Reader.IsDebug = false; long[] inpt = Reader.ReadLine().Split(' ').Select(a=>long.Parse(a)).ToArray(); long times = inpt[0]; long count = inpt[1]; long[] list = new long[times + 1]; list[1] = 1; list[2] = 1; for(long i = 3; i<= times; i++) { int idx = (int)i; list[idx] = list[idx-1] + list[idx - 2]; } long sa = list[times] - count; this.NumList = list.Reverse().ToArray(); int ans = this.GetAns(0, sa); Console.WriteLine(ans); } Dictionary> dic = new Dictionary>(); private int GetAns(int idx, long remain) { if(!this.dic.ContainsKey(idx)) { this.dic.Add(idx, new Dictionary()); } if(dic[idx].ContainsKey(remain)) { return dic[idx][remain]; } if(remain == 0) { return 0; } if(idx == this.NumList.Length - 1) { if(remain == this.NumList.Last()) { return 1; } else { return -1; } } int ans = -1; if(this.NumList.ToList().IndexOf(remain) >= idx) { ans = 1; } else if(this.NumList.Skip(idx).Sum(a=>a) < remain) { ans = -1; } else { int ret = this.GetAns(idx+1, remain); if(ret >= 0) { if(ans < 0) { ans = ret; } else { ans = Math.Min(ans, ret); } } if(remain >= this.NumList[idx]) { ret = this.GetAns(idx+1, remain - this.NumList[idx]); if(ret >= 0) { ret++; if(ans < 0) { ans = ret; } else { ans = Math.Min(ans, ret); } } } } this.dic[idx].Add(remain, ans); return ans; } private long[] NumList; public class Reader { public static bool IsDebug = true; private static String PlainInput = @" 67 17308070087783 "; 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(); } }