#include using namespace std; const int N = 100000; struct Node { int pos; int step; }; int main() { int n, k; //农夫位置,牛的位置 cin >> n >> k; queue q; q.push({n, 0}); //农夫位置,步数 while (q.size()) { auto t = q.front(); q.pop(); //出口 if (t.pos == k) { cout << t.step << endl; break; } if (t.pos + 1 <= N) q.push({t.pos + 1, t.step + 1}); if (t.pos - 1 >= 0) q.push({t.pos - 1, t.step + 1}); if (t.pos <= t.pos * 2) q.push({t.pos * 2, t.step + 1}); } return 0; }