 Contests Virtual Contests Problems Submit Runs Status Rank List Forum

3071.   Number Game
Time Limit: 1.0 Seconds   Memory Limit: 65536K
Total Runs: 964   Accepted Runs: 396

There is an interesting game. We start with a number K. Then three operations is allowed:

1. Multiply current number by 2
2. Divide current number by 2, if current number is even.
3. Increase current number by 1

Our target is to get number P with minimum operations. You can assume 0 < P,K < 100000, and the number can not be greater than or equal to 100000 at any time.

### Input

The first line is an integer T, the number of test cases. Then T cases follows.

Each test case contain two numbers K and P in one line separated by a space.

### Output

Output the minimum number of operations. If it is impossible to get P from K, output -1 instead.

### Sample Input

2
11 20
99999 50000


### Sample Output

7
-1


### Hint:

For the first sample, the operation is 11 -> 12 -> 6 -> 3 -> 4 -> 5 -> 10 -> 20.

For the second sample, even though we can get 99999 -> 100000 -> 50000, but the number is not allowed to be greater than or equal to 100000.

Source: TJU Exam 2008
Submit   List    Runs   Forum   Statistics

Tianjin University Online Judge v1.3.0
Maintance:Fxz. Developer: SuperHacker, G.D.Retop, Fxz