CF1152C.Neko does Maths
普及+/提高
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Neko loves divisors. During the latest number theory lesson, he got an interesting exercise from his math teacher.
Neko has two integers a and b. His goal is to find a non-negative integer k such that the least common multiple of a+k and b+k is the smallest possible. If there are multiple optimal integers k, he needs to choose the smallest one.
Given his mathematical talent, Neko had no trouble getting Wrong Answer on this problem. Can you help him solve it?
Neko 非常喜欢约数。在最近的一节数论课上,他的数学老师给他布置了一道有趣的习题。
Neko 有两个整数 a 和 b。他的目标是找到一个非负整数 k,使得 a+k 与 b+k 的最小公倍数(LCM)尽可能小。如果存在多个使最小公倍数达到最小值的最优整数 k,他需要选择其中最小的一个。
凭借其数学天赋,Neko 在这道题上毫无困难地得到了“答案错误”(Wrong Answer)。你能帮他解决这个问题吗?
输入格式
The only line contains two integers a and b (1≤a,b≤109).
唯一的一行包含两个整数 a 和 b(1≤a,b≤109)。
输出格式
Print the smallest non-negative integer k (k≥0) such that the lowest common multiple of a+k and b+k is the smallest possible.
If there are many possible integers k giving the same value of the least common multiple, print the smallest one.
输出使得 a+k 与 b+k 的最小公倍数(LCM)取到最小值的最小非负整数 k(即 k≥0)。
若存在多个 k 值使得最小公倍数相同,则输出其中最小的一个。
输入输出样例
输入#1
6 10
输出#1
2
输入#2
21 31
输出#2
9
输入#3
5 10
输出#3
0
说明/提示
In the first test, one should choose k=2, as the least common multiple of 6+2 and 10+2 is 24, which is the smallest least common multiple possible.
在第一个测试用例中,应选择 k=2,因为 6+2 与 10+2 的最小公倍数为 24,这是可能的最小公倍数。
输入解题思路,AI测评打分。不知道怎么写?