You are given two positive integers, 'a' and 'b'.
Your task is to find the smallest possible sum of x + y, where x and y are non-negative integers that you can add to 'a' and 'b' respectively, such that the resulting number (b + y) is perfectly divisible by the resulting number (a + x).
The first line of input contains two space-separated integers, 'a' and 'b'.
Print a single integer representing the minimum possible value of x + y.
x and y must be greater than or equal to 0.
The condition to satisfy is (b + y) % (a + x) == 0.
6 10
2
We need to find non-negative `x` and `y` to minimize `x + y` such that `(10 + y) % (6 + x) == 0`.
- Let's try `x = 0`. We need `(10 + y)` to be a multiple of `6`. The smallest multiple of 6 that is >= 10 is 12. So, `10 + y = 12` which gives `y = 2`. The sum `x + y = 0 + 2 = 2`.
- Let's try `y = 0`. We need `10` to be a multiple of `6 + x`. The smallest number >= 6 that divides 10 is 10 itself. So, `6 + x = 10` which gives `x = 4`. The sum `x + y = 4 + 0 = 4`.
The minimum sum found is 2.
4 12
0
We are given a=4 and b=12.
If we choose `x = 0` and `y = 0`, we get:
- `a + x = 4`
- `b + y = 12`
Since `12 % 4 == 0`, the condition is already satisfied. The minimum sum `x + y` is 0.
The expected time complexity is O(sqrt(B))
1 <= a, b <= 1000
Time limit: 1sec
The expected time complexity is O(sqrt(B))