#include int bit_count(int); int main(void){ int N; int location=1; //現在のマスの位置 int bit=0; // 何ビット進むかor戻るか int sum; int times=1; //移動回数 scanf("%d",&N); while(location != N){ bit = bit_count(location); sum = location + bit; if(sum <= N) location += bit; else location -= bit; times++; sum=0; } printf("%d",times); return 0; } int bit_count(int n) { int bit_counter=0; while(n>=1) { if(n%2==1) bit_counter++; n=n/2; } return bit_counter; }