#include<bits/stdc++.h> using namespace std; int n,m; struct Node{ long long x,step; }; queue<Node> q; int a[1000000]; int main(){ cin>>n>>m; q.push({n,0}); while(q.size()>0){ a[n]=1; long long x=q.front().x; long long step=q.front().step; if(x==m){ cout<<step; return 0; } if(a[x+1]==0&&x<=m){ a[x+1]=1; q.push({x+1,step+1}); } if(a[x-1]==0&&x>=1){ a[x-1]=1; q.push({x-1,step+1}); } if(a[x*2]==0&&x<=m){ a[x*2]=1; q.push({x*2,step+1}); } q.pop(); } return 0; } /************************************************************** Problem: 2111 User: chenjingqi Language: C++ Result: Accepted Time:59 ms Memory:6116 kb ****************************************************************/