eolymp
bolt
Try our new interface for solving problems
Problems

Important scientific number

Important scientific number

Pin was assembling his very important new invention, but at some point he discovered that he had made a mistake in one of the formulas and could have assembled the corresponding part incorrectly. After carefully looking at the detail and correcting the formula, Pin noted that now the part contains two gears with $a$ and $b$ teeth, respectively, and it will work correctly with gears of sizes $a + x$ and $b + x$ respectively, where $x$ is a non-negative integer such that $a + x$ is divisible by $b$ and $b + x$ is divisible by $a$. Pin is very tired, so he asks you to help him find such a non-negative $x$ that satisfies the given conditions. Because Pin doesn't like big gears, the minimum of all possible $x$ values should be chosen. \InputFile One line contains two numbers $a$ and $b~(1 \le a, b \le 10^9)$ --- the sizes of the gears in the detail. \OutputFile Print one non-negative integer $x$ --- the minimum number of teeth missing in the gears for the invention to work correctly.
Time limit 1 second
Memory limit 128 MiB
Input example #2
8 1
Output example #2
7
Input example #3
3 4
Output example #3
5
Input example #4
123 123
Output example #4
0
Source 2020 Cycle of Internet Olympiads for schoolchildren, First team contest, October 18, Problem А