#include int N; //行ったことがあったら1 int dp[10000]; int getbit(int x); main(){ scanf("%d",&N); int step = 1; int point = 1; while(point != N){ printf("%d ",point);// //ループ確定 if(dp[point-1]){ step = -1; break; } if(point + getbit(point) <= N){ //前にすすめる場合 step++; dp[point-1] = 1; point += getbit(point); }else{ //後ろに進む step++; dp[point-1] = 1; point -= getbit(point); } } printf("\n%d",step); return 0; } int getbit(int x){ return __builtin_popcountl(x); }