Minimizing the LCM
Time limit1sMemory limit256 MB
Find the smallest N of at least 1 that minimizes the least common multiple of A+N and B+N.
- Level
Medium6 of 10
- Topics
- Number theory, Math
- Solved
- No attempts yet
Problem
You are given two natural numbers and . Find the natural number that makes the least common multiple of and as small as possible.
Input
The first line contains two natural numbers and , separated by a space. .
Output
Print on the first line. If several values of make the least common multiple minimal, print the smallest one.
Note
A natural number is an integer of at least 1, so .