#550. CF1152C Neko does Maths

CF1152C Neko does Maths

题目描述

Neko loves divisors. During the latest number theory lesson, he got an interesting exercise from his math teacher.

Neko has two integers a a and b b . His goal is to find a non-negative integer k k such that the least common multiple of a+k a+k and b+k b+k is the smallest possible. If there are multiple optimal integers k 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?

翻译:

给定两个正整数a,ba,b,找到非负整数kk使a+ka+kb+kb+k的最小公倍数最小,如有多解输出最小的kk

输入格式

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

输出格式

Print the smallest non-negative integer k k ( k0 k \ge 0 ) such that the lowest common multiple of a+k a+k and b+k b+k is the smallest possible.

If there are many possible integers k 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 k = 2 , as the least common multiple of 6+2 6 + 2 and 10+2 10 + 2 is 24 24 , which is the smallest least common multiple possible.