文件目录

#include <bits/stdc++.h>
using namespace std;
int n, k;
struct node
{
    int x, step;
};
int bfs(int x)
{
    queue<node> q;
    q.push((node){x, 0});
    bool vis[100005] = {};
    vis[x] = true;
    while (!q.empty())
    {
        node u = q.front();
        q.pop();
        if (u.x == k)
            return u.step;
        if (u.x - 1 >= 0 && !vis[u.x - 1])
        {
            vis[u.x - 1] = true;
            q.push((node){u.x - 1, u.step + 1});
        }
        if (u.x + 1 <= 100000 && !vis[u.x + 1])
        {
            vis[u.x + 1] = true;
            q.push((node){u.x + 1, u.step + 1});
        }
        if (u.x * 2 <= 100000 && !vis[u.x * 2])
        {
            vis[u.x * 2] = true;
            q.push((node){u.x * 2, u.step + 1});
        }
    }
    return -1;
}
int main()
{
    cin >> n >> k;
    cout << bfs(n);
    return 0;
}