#include <bits/stdc++.h>
using namespace std;
long long n,tmp,l[200005];
void bfs()
{
queue <int> q;
q.push(1);
l[1]=0;
while(!q.empty())
{
tmp=q.front();
if(tmp==n)
{
cout<<l[n];
return;
}
if(tmp-1>0&&l[tmp-1]==-1)
{
q.push(tmp-1);
l[tmp-1]=l[tmp]+1;
}
if(tmp+1<=n&&l[tmp+1]==-1)
{
q.push(tmp+1);
l[tmp+1]=l[tmp]+1;
}
if(tmp*2<=n&&l[tmp*2]==-1)
{
q.push(tmp*2);
l[tmp*2]=l[tmp]+1;
}
q.pop();
}
return;
}
int main()
{
cin>>n;
memset(l,-1,sizeof(l));
bfs();
return 0;
}
20分,其余RE,求大佬帮忙改正