Skip to content

Latest commit

 

History

History
21 lines (21 loc) · 18.9 KB

Task.md

File metadata and controls

21 lines (21 loc) · 18.9 KB

Rumour

Time limit: 1280 ms
Memory limit: 264 MB

Consider a full binary tree with an infinite number of levels. The vertices are labeled with positive integers, starting from the root and moving down the tree, from left to right on each level. In the example below you can see the first 444 levels of the tree:

123456789101112131415

Answer qqq (1≤q≤106)(1 \leq q \leq 10^6)(1q106) queries of the form: find the minimum distance between vertices aaa and bbb (1≤a,b≤1018)(1 \leq a, b \leq 10^{18})(1a,b1018).

Standard input

The first line contains integer qqq.

The next qqq lines contain two integers, aaa and bbb.

Standard output

Print qqq lines, on line iii the answer for the ithi^{th}ith query.

Constraints and notes

  • 1≤q≤1061 \leq q \leq 10^61q106
  • 1≤a,b≤10181 \leq a, b \leq 10^{18}1a,b1018

InputOutput
4
1 1
1 2
2 3
10 6
0
1
2
5