题库练习 Johnny and Ancient Computer
← 上一题 下一题 →

A13531 | Johnny and Ancient Computer

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

Johnny has recently found an ancient, broken computer. The machine has only one register, which allows one to put in there one variable. Then in one operation, you can shift its bits left or right by at most three positions. The right shift is forbidden if it cuts off some ones. So, in fact, in one operation, you can multiply or divide your number by $2$ , $4$ or $8$ , and division is only allowed if the number is divisible by the chosen divisor.

Formally, if the register contains a positive integer $x$ , in one operation it can be replaced by one of the following:

- $x \cdot 2$
- $x \cdot 4$
- $x \cdot 8$
- $x / 2$ , if $x$ is divisible by $2$
- $x / 4$ , if $x$ is divisible by $4$
- $x / 8$ , if $x$ is divisible by $8$

For example, if $x = 6$ , in one operation it can be replaced by $12$ , $24$ , $48$ or $3$ . Value $6$ isn't divisible by $4$ or $8$ , so there're only four variants of replacement.

Now Johnny wonders how many operations he needs to perform if he puts $a$ in the register and wants to get $b$ at the end.

输入格式

The input consists of multiple test cases. The first line contains an integer $t$ ( $1 \leq t \leq 1000$ ) — the number of test cases. The following $t$ lines contain a description of test cases.

The first and only line in each test case contains integers $a$ and $b$ ( $1 \leq a, b \leq 10^{18}$ ) — the initial and target value of the variable, respectively.

输出格式

Output $t$ lines, each line should contain one integer denoting the minimum number of operations Johnny needs to perform. If Johnny cannot get $b$ at the end, then write $-1$ .

输入输出样例

输入 #1
10
10 5
11 44
17 21
1 1
96 3
2 128
1001 1100611139403776
1000000000000000000 1000000000000000000
7 1
10 8
输出 #1
1
1
-1
0
2
2
14
0
-1
-1
C++ 编辑器
输入
输出