丢失的牛
#include<iostream>
using namespace std;
int main()
{
int n, m;
cin >>n >>m;
int res = 0;
int num = 1, cnt = 1;
for(int i = n;;)
{
if(cnt % 2 != 0 ||cnt == 1)
{
if(n < m && n + num >= m){
res += m - i;
break;
}
res += n + num - i;
i = n + num;
}
else {
if(n > m && n - num <= m){
res += i - m;
break;
}
res += i - n + num;
i = n - num;
}
num *= 2;
cnt ++;
}
cout << res <<endl;
}