CF1543A.Exciting Bets
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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 a dollars and Ronnie has bet b dollars. But the fans seem to be disappointed. The excitement of the fans is given by gcd(a,b), where gcd(x,y) denotes the greatest common divisor (GCD) of integers x and y. To make the race more exciting, you can perform two types of operations:
- Increase both a and b by 1.
- Decrease both a and b by 1. This operation can only be performed if both a and b are greater than 0.
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 gcd(x,0)=x for any x≥0.
欢迎来到罗克波特市!
现在是游戏中你与罗尼的首次比赛!为了让比赛更有趣,你下注了 a 美元,而罗尼下注了 b 美元。但粉丝们似乎感到失望。粉丝们的兴奋度由 gcd(a,b) 给出,其中 gcd(x,y) 表示整数 x 和 y 的最大公约数(GCD)。为了使比赛更加精彩,你可以执行以下两种操作:
- 将 a 和 b 同时增加 1;
- 将 a 和 b 同时减少 1;此操作仅当 a>0 且 b>0 时才可执行。
每次移动中,你可任选执行其中一种操作。你可以执行任意次(包括零次)操作。请确定粉丝所能获得的最大兴奋度,以及达到该最大兴奋度所需的最少操作次数。
注意:对任意 x≥0,有 gcd(x,0)=x。
输入格式
The first line of input contains a single integer t (1≤t≤5⋅103) — the number of test cases.
The first and the only line of each test case contains two integers a and b (0≤a,b≤1018).
输入的第一行包含一个整数 t(1≤t≤5⋅103)—— 表示测试用例的数量。
每个测试用例仅有一行,包含两个整数 a 和 b(0≤a,b≤1018)。
输出格式
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.
对于每个测试用例,输出一行,包含两个整数。
如果粉丝们可以获得无限的兴奋值,则输出 0 0。
否则,第一个整数必须是粉丝们能获得的最大兴奋值,第二个整数必须是达到该兴奋值所需的最少移动次数。
输入输出样例
输入#1
4 8 5 1 2 4 4 3 9
输出#1
3 1 1 0 0 0 6 3
说明/提示
For the first test case, you can apply the first operation 1 time to get a=9 and b=6. It can be shown that 3 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 1. Since the initial excitement is also 1, 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 3 times to get a=0 and b=6. Since, gcd(0,6)=6, the fans will get an excitement of 6.
对于第一个测试用例,你可以执行第一次操作 1 次,得到 a=9 和 b=6。可以证明,最大可能的兴奋值为 3。
对于第二个测试用例,无论你执行多少次操作,粉丝的兴奋值始终为 1。由于初始兴奋值也为 1,因此无需执行任何操作。
对于第三个测试用例,粉丝可以通过无限次执行第一次操作获得无限大的兴奋值。
对于第四个测试用例,你可以执行第二次操作 3 次,得到 a=0 和 b=6。由于 gcd(0,6)=6,粉丝将获得兴奋值 6。
输入解题思路,AI测评打分。不知道怎么写?