A14458 | Exciting Bets
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers $x$ and $y$ . To make the race more exciting, you can perform two types of operations:
1. Increase both $a$ and $b$ by $1$ .
2. 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 \ge 0$ .
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)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers $x$ and $y$ . To make the race more exciting, you can perform two types of operations:
1. Increase both $a$ and $b$ by $1$ .
2. 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 \ge 0$ .
输入格式
The first line of input contains a single integer $t$ ( $1\leq t\leq 5\cdot 10^3$ ) — the number of test cases.
The first and the only line of each test case contains two integers $a$ and $b$ ( $0\leq a, b\leq 10^{18}$ ).
The first and the only line of each test case contains two integers $a$ and $b$ ( $0\leq a, b\leq 10^{18}$ ).
输出格式
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.
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.
输入输出样例
输入 #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$ .
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$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted