#include <bits/stdc++.h>
using namespace std;

#define X first
#define Y second

int dx[]={-1,1};
int n,k;
int board[200005];


int main() {
    ios::sync_with_stdio(0);
    fill(board,board+200005,-1);
    cin.tie(0);
    cin >> n >> k;

    board[n]=0;
    deque<int> dq;
    dq.push_back(n);
    
    while(!dq.empty()) {
        int cur=dq.front(); dq.pop_front();
        //찾음
        if(cur==k) {
            cout << board[cur];
            return 0;
        }
        int nx=cur*2;
        if(nx>=0 && nx<200005 && board[nx]==-1) {
            board[nx]=board[cur];
            dq.push_front(nx);
        }

        for(int idx=0; idx<2; idx++) {
            int nx=cur+dx[idx];
            if(nx<0|| nx>200005) continue;
            if(board[nx]!=-1) continue;
            
            board[nx]=board[cur]+1;
            dq.push_back(nx);
        }
    }
    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: