#include #include #include using namespace std; int func(int a) { a = (a & 0x5555) + ((a >> 1) & 0x5555); a = (a & 0x3333) + ((a >> 2) & 0x3333); a = (a & 0x0F0F) + ((a >> 4) & 0x0F0F); a = (a & 0x00FF) + ((a >> 8) & 0x00FF); return a; } int main() { std::ios::sync_with_stdio(false); std::cin.tie(0); int n; cin >> n; vector vec(n + 1, 0); //既に来たかどうか vec.at(1) = 1; //at(1)には既に来てる = 1 , 他はまだ行ってない = 0 queue q; q.push(1); int count = 1; //移動数 while (!q.empty()) { int position = q.front(); q.pop(); int step = func(position); //戻るとき if (position - step > 0 && vec.at(position - step) == 0) { q.push(position - step); vec.at(position - step) = 1; count++; } //進むとき if (position + step <= n && vec.at(position + step) == 0) { q.push(position + step); vec.at(position + step) = 1; count++; } } if (vec.at(n) == 0) { cout << "-1" << endl; } else { cout << count << endl; } return 0; } // 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16... // 1 1 2 1 2 2 3 1 2 2 3 2 3 3 4 1...