P15710 [CodeChef] BINSHFFL
提高-
题目描述

Read problems statements in Mandarin chinese, Russian and Vietnamese as well.

Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero):
write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any)
shuffle the binary digits of $A$ in an arbitrary way, obtaining a number $s$
replace $A$ by $s+1$

Chef is wondering about the minimum number of operations he has to perform on $A$ in order to obtain $B$. Compute this number or determine that it is impossible.

------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains two space-separated integers $A$ and $B$.

------ Output ------
For each test case, print a single line containing one integer — the minimum number of operations or $-1$ if it is impossible to obtain $B$ from $A$.

------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$0 ≤ A, B ≤ 10^{18}$

------ Subtasks ------
Subtask #1 (20 points): $A, B ≤ 2^{7}$

Subtask #2 (80 points): original constraints

----- Sample Input 1 ------
2
2 4
1 5
----- Sample Output 1 ------
2
1
----- explanation 1 ------
Example case 1: One optimal solution is to not shuffle anything, so Chef just adds $1$ twice.

Example case 2: We can obtain $5$ from $1$ in one operation.

输入格式

见题面

输出格式

见题面

样例输入
2 2 4 1 5
样例输出
2 1