Smallest LCM

Problem Statement: You are given two natural numbers A and B. Determine the natural number N such that the lowest common multiple i.e. lcm(A+N, B+N) is minimum.

If there are several values of N which yield the minimum, output the smallest one.

1 \leq A, B \leq 10^9

Sample Input:
A = 4, B = 10
Sample Output:

How can I approach the above problem?
I am not strong with number theory, so please give your explanations with every step explained.
It would be great if you can give me a mathematical proof of the correctness of your algorithm.

1 Like

See the tutorial.

1 Like

Thanks man.


1 Like