#include<bits/stdc++.h> using namespace std; int n,m,a[100001]; struct Node{ int x,step; }; int fx[3]={-1,1,2}; queue<Node> q; int main(){ cin>>n>>m;//5 17 q.push({n,0}); a[n]=1; while(q.size()>0){ int x=q.front().x; int step=q.front().step; for(int i=0;i<=2;i++){ int tx; if(fx[i]==2) tx=x*2; else tx=x+fx[i]; if(tx==m){ cout<<step+1; return 0; } else{ if(a[tx]==0){ a[tx]=1; q.push({tx,step+1}); } } } q.pop(); } return 0; } /************************************************************** Problem: 2111 User: hulaoshi Language: C++ Result: Runtime Error ****************************************************************/