#include<bits/stdc++.h> using namespace std; int n,m; struct Node{ int x,step; }; queue<Node> q; int main(){ cin>>n>>m; q.push({n,0}); while(q.size()>0){ int x=q.front().x; int step=q.front().step; if(x+1==m){ cout<<step+1; return 0; } else { q.push({x+1,step+1}); } if(x-1==m){ cout<<step+1; return 0; } else { q.push({x-1,step+1}); } if(x*2==m){ cout<<step+1; return 0; } else { q.push({x*2,step+1}); } q.pop(); } return 0; } /************************************************************** Problem: 2111 User: chenjingqi Language: C++ Result: Memory Limit Exceed ****************************************************************/