欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1362A.Johnny and Ancient Computer
Johnny and Ancient Computer
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 , or , and division is only allowed if the number is divisible by the chosen divisor.
Formally, if the register contains a positive integer , in one operation it can be replaced by one of the following:
- , if is divisible by
- , if is divisible by
- , if is divisible by
For example, if , in one operation it can be replaced by , , or . Value isn't divisible by or , so there're only four variants of replacement.
Now Johnny wonders how many operations he needs to perform if he puts in the register and wants to get at the end.
Input
The input consists of multiple test cases. The first line contains an integer () — the number of test cases. The following lines contain a description of test cases.
The first and only line in each test case contains integers and () — the initial and target value of the variable, respectively.
Output
Output lines, each line should contain one integer denoting the minimum number of operations Johnny needs to perform. If Johnny cannot get at the end, then write .
Note
In the first test case, Johnny can reach from by using the shift to the right by one (i.e. divide by ).
In the second test case, Johnny can reach from by using the shift to the left by two (i.e. multiply by ).
In the third test case, it is impossible for Johnny to reach from .
In the fourth test case, initial and target values are equal, so Johnny has to do operations.
In the fifth test case, Johnny can reach from by using two shifts to the right: one by , and another by (i.e. divide by and by ).
Samples
10
10 5
11 44
17 21
1 1
96 3
2 128
1001 1100611139403776
1000000000000000000 1000000000000000000
7 1
10 8
1
1
-1
0
2
2
14
0
-1
-1
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |