#include using namespace std; int getBitNum(int x) { int ret = 0; while(x) { x &= (x-1); ++ ret; } return ret; } int main(int argc, char** argv) { int MAX = 10001; int NOSERACH = MAX; int route[MAX]; for (int ii=0; ii> n; queue que; que.push(1); while(!que.empty()) { int pos = que.front(); que.pop(); int mlen = getBitNum(pos); int move[2] = {mlen, -mlen}; for (int ii=0; ii<2; ++ii) { int newPos = pos + move[ii]; if (newPos<1 || newPos>n) continue; if (route[newPos] != NOSERACH) continue; route[newPos] = route[pos] + 1; que.push(newPos); } } if (route[n]==NOSERACH) cout << -1 << endl; else cout << (route[n]) << endl; return 0; }