A12489 | Neko does Maths
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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 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?
输入格式
The only line contains two integers $a$ and $b$ ( $1 \le a, b \le 10^9$ ).
输出格式
Print the smallest non-negative integer $k$ ( $k \ge 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.
If there are many possible integers $k$ giving the same value of the least common multiple, print the smallest one.
输入输出样例
输入 #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.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted