# 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.

Constraints:
1 \leq A, B \leq 10^9

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

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.
Thanks

1 Like

https://codeforces.com/problemset/problem/1152/C

See the tutorial.

1 Like

Thanks man.

1 Like