using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using static System.Console; using static System.Math; public class Solve{ static public int mod = 1000000007; static public string al = "abcdefghijklmnopqrstuvwxyz"; public static void Main(){ // 方針 // var n = rint(); var move = new int[n+1]; for(int i=1;i<=n;i++){ var temp = i; while(temp > 0){ if(temp %2 == 1)move[i]++; temp/=2; } } //WriteLine(string.Join(" ",move)); var queue = new Queue(); var length = new int[n+1]; for(int i=2;i<=n;i++){ length[i] = -1; } length[1] = 1; //var passed = new bool[n+1]; queue.Enqueue(1); while(queue.Count > 0){ var de = queue.Dequeue(); //WriteLine(de); //if(passed[de]) continue; //passed[de] = true; if(de+move[de] <= n){ if(length[de+move[de]] > length[de]+1 || length[de+move[de]] == -1){ length[de+move[de]] = length[de]+1; queue.Enqueue(de+move[de]); } } if(de-move[de] > 0){ //WriteLine(de-move[de]); if(length[de-move[de]] > length[de]+1 || length[de-move[de]] == -1){ length[de-move[de]] = length[de]+1; queue.Enqueue(de-move[de]); } } } WriteLine(length[n]); } public static void swap(ref int a,ref int b){int temp = a;a= b;b = temp;} static void charswap(ref char a,ref char b){char temp = a;a= b;b = temp;} static int ncr(int n,int r){if(n=0;i--){if(binary[i] == '1'){value = value*a_power%mod;}a_power = a_power*a_power%mod;}return (int)value;} static int square2(int a,int b){long output = 1;var list = new List();int sh = 1;long n = a;list.Add(a);while(sh < b){sh *= 2;n = n*n%mod;list.Add(n);}for(int i=list.Count-1;i>=0;i--){if(b > sh){b -= sh;sh /= 2;output = output*list[i]%mod;}}return (int)output;} //各種読取 static string rstr(){ return ReadLine(); } static int rint(){ return int.Parse(ReadLine()); } static long rlong(){ return long.Parse(ReadLine()); } static string[] stra(){ return ReadLine().Split(' '); } static char[] chara(){ string[] a=stra();string b="";for(int i=0;i