An Important Scientific Number
InterviewTime limit2sMemory limit1024 MB
Given gear sizes a and b, find the smallest non-negative x so that b divides a+x and a divides b+x.
- Level
Medium4 of 10
- Topics
- Number theory, Math
- Solved
- No attempts yet
Statement
Ping was assembling his very important new invention when he realized he had made a mistake in one of the formulas, and the corresponding gear may have been assembled incorrectly.
After looking closely at the part and fixing the formula, Ping noticed that the part currently has two gears with and teeth. To work correctly, the gears must have and teeth, where is a non-negative integer such that is divisible by and is divisible by .
Ping is very tired, so he asks you to find a non-negative that satisfies these conditions. Ping does not like large gears, so among all suitable values of , choose the smallest one.
Input
A single line contains two space-separated integers and , the sizes of the gears in the part ().
Output
Print one integer , the smallest non-negative value that satisfies the conditions. This is the minimum number of teeth the gears are missing for the invention to work correctly.