@@ -0,0 +1,45 @@
+#include <cstdio>
+#include <cstring>
+#include <queue>
+
+using namespace std;
+const int L = 200001;
+bool set[L];
+int main() {
+ int N, K;
+ scanf("%d %d", &N, &K);
+ queue<int> q;
+ q.push(N);
+ memset(set, 0, sizeof(set));
+ set[N] = true;
+ int s = 1, t = 0;
+ while (s != 0) {
+ int n = q.front();
+ q.pop();
+ s--;
+ if (n == K) break;
+ if (n < K) {
+ if (!set[2 * n]) {
+ q.push(2 * n);
+ set[2 * n] = true;
+ }
+ if (!set[n + 1]) {
+ q.push(n + 1);
+ set[n + 1] = true;
+ if (0 < n && !set[n - 1]) {
+ q.push(n - 1);
+ set[n - 1] = true;
+ if (s == 0) {
+ s = q.size();
+ t++;
+ printf("%d\n", t);
+ return 0;
+}