using System; using System.Linq; namespace No003_ビットすごろく { class Program { static private int N; static private int[] Bit; static private bool[] Checker; static void Main(string[] args) { N = int.Parse(Console.ReadLine()); BitCheck(); Console.WriteLine(Recursive(1, 1).ToString()); } static void BitCheck() { int[] log2 = new int[N + 1]; int temp, count; Bit = new int[N + 1]; Checker = Enumerable.Repeat(false, N + 1).ToArray(); log2[0] = 1; log2[1] = 1; Bit[0] = 0; Bit[1] = 1; temp = 1; count = 0; for (int i = 2; i <= N; i++) { log2[i] = (int)Math.Log((double)i, 2.0) + 1; if (log2[i] != temp) { temp = log2[i]; count = 0; } Bit[i] = Bit[count] + 1; count++; } } static int Recursive(int level, int count) { if (Checker[level]) return -1; else if (level == N) return count; Checker[level] = true; if (level + Bit[level] <= N) return Recursive(level + Bit[level], count + 1); else return Recursive(level - Bit[level], count + 1); } } }