Leaderboard
Showing:
Shortest distance in infinite tree
Easy Accuracy: 46.72% Submissions: 4018 Points: 2

Consider you have an infinite long binary tree having a pattern as below
               1
           2      3
        4  5    6  7
    .  .  .  .   .  .  .  . 
You are given two nodes with values x and y, the task is to find the length of the shortest path between the two nodes.

Input:
The first line of input contains an integer T denoting the no of test cases. Then T test cases follow. Each test case contains two space separated integers x and y.

Output:
For each test case in a new line print the shortest length of the path from x to y.


Constraints:
1<=T<=1000
1<=x,y<=10^7

Example:
Input:

2
1 3
2 2
Output:
1
0


 

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.

Shortest distance in infinite tree

Output Window