题目描述
Chef has two integers X and Y. Chef wants to perform some operations to make both X and Y zero simultaneously. In one operation, Chef can either:
set X :$= 2 \cdot X$
or set Y :$= 2 \cdot Y$
or set X := X - 1 and Y := Y - 1
Chef is a little busy with preparing the contest. Help him find the minimum number of operations required to make both X and Y equal to 0 simultaneously. If it is impossible to do so after any number of operations, print -1.
------ Input Format ------
- The first line contains a single integer T — the number of test cases. Then the test cases follow.
- The first and only line of each test case contains two space separated integers X and Y.
------ Output Format ------
For each test case, print the minimum number of operations required to make X and Y zero simultaneously. If it is impossible to do so after any number of operations, print -1 instead.
------ Constraints ------
$1 ≤ T ≤ 3 \cdot 10^{5}$
$0 ≤ X , Y ≤ 10^{18}$
----- Sample Input 1 ------
2
1 2
99999999999999999 99999999999999999
----- Sample Output 1 ------
3
99999999999999999
----- explanation 1 ------
Let $(x, y)$ denote the values of $X$ and $Y$ respectively.
Test case 1: Three operations are required: $(1, 2) \xrightarrow{X := X \cdot 2}{} (2, 2) \xrightarrow[Y := Y - 1]{X := X - 1} (1, 1) \xrightarrow[Y := Y - 1]{X := X - 1} (0, 0)$
It can be proven that it is impossible in fewer operations.
输入格式
见题面
输出格式
见题面