欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1543A.Exciting Bets
Exciting Bets
Welcome to Rockport City!
It is time for your first ever race in the game against Ronnie. To make the race interesting, you have bet dollars and Ronnie has bet dollars. But the fans seem to be disappointed. The excitement of the fans is given by , where denotes the greatest common divisor (GCD) of integers and . To make the race more exciting, you can perform two types of operations:
- Increase both and by .
- Decrease both and by . This operation can only be performed if both and are greater than .
In one move, you can perform any one of these operations. You can perform arbitrary (possibly zero) number of moves. Determine the maximum excitement the fans can get and the minimum number of moves required to achieve it.
Note that for any .
Input
The first line of input contains a single integer () — the number of test cases.
The first and the only line of each test case contains two integers and ().
Output
For each test case, print a single line containing two integers.
If the fans can get infinite excitement, print 0 0.
Otherwise, the first integer must be the maximum excitement the fans can get, and the second integer must be the minimum number of moves required to achieve that excitement.
Note
For the first test case, you can apply the first operation time to get and . It can be shown that is the maximum excitement possible.
For the second test case, no matter how many operations you apply, the fans will always have an excitement equal to . Since the initial excitement is also , you don't need to apply any operation.
For the third case, the fans can get infinite excitement by applying the first operation an infinite amount of times.
For the fourth test case, you can apply the second operation times to get and . Since, , the fans will get an excitement of .
Samples
4
8 5
1 2
4 4
3 9
3 1
1 0
0 0
6 3
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |