Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define ll long long
- #define el endl
- #define umi unordered_map<int, int>
- #define umll unordered_map<ll, ll>
- #define all(vect) vect.begin(), vect.end()
- #define reset(A) memset(A, 0, sizeof(A))
- #define approx(n) fixed << setprecision(n)
- const int mod = 1e9 + 7;
- using namespace std;
- void solve()
- {
- ll st, en;
- cin >> st >> en;
- queue<ll> q;
- q.push(st);
- umll mp;
- mp[st] = 1;
- if(st == en)
- {
- cout << 0 << el;
- return;
- }
- while(true)
- {
- ll te = q.front();
- mp[te]++;
- q.pop();
- if(te == en)
- {
- break;
- }
- if(!mp[te - 1])
- q.push(te - 1);
- if(!mp[te * 2])
- q.push(te * 2);
- }
- ll count = mp.size();
- if(count)
- cout << (ll)log2(count) << el;
- }
- int main()
- {
- int t = 1;
- cin >> t;
- // cin.ignore();
- while(t--)
- {
- solve();
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment