Preparando MOJI

Neko does Maths

1000ms 262144K

Description:

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?

Input:

The only line contains two integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 10^9$$$).

Output:

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.

Sample Input:

6 10

Sample Output:

2

Sample Input:

21 31

Sample Output:

9

Sample Input:

5 10

Sample Output:

0

Note:

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.

Informação

Codeforces

Provedor Codeforces

Código CF1152C

Tags

brute forcemathnumber theory

Submetido 0

BOUA! 0

Taxa de BOUA's 0%

Datas 09/05/2023 09:46:57

Relacionados

Nada ainda