aboutsummaryrefslogtreecommitdiff
path: root/codechef/ShortestPathInBinaryTrees/main.cpp
blob: eb5f641bcc8f7c80bb281c1b0e936037ef33591a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include<bits/stdc++.h>

using namespace std;

int main () {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int tt;
	cin >> tt;
	while(tt--){
    int i, j;
    cin >> i >> j;
    int ans = 0;
    while(i != j) {
      if (j > i) {
        j /= 2;
      } else {
        i /= 2;
      }
      ans++;
    }
    cout << ans << '\n';
	}
}