using System; using System.Linq; namespace No00003_BitSugoroku { internal class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); bool[] map = new bool[n]; int index = 1; int count = 0; while (true) { count++; if (index == n) { break; } if (map[index]) { count = -1; break; } map[index] = true; int diff = Convert.ToString(index, 2).Count(x => x == '1'); if (index + diff <= n) { index += diff; } else { index -= diff; } } Console.WriteLine(count); } } }