Given two numbers X and Y. the duty is to seek out the quantity N (N ≤ 10^18) which satisfies these two circumstances:
- (N + X) is divisible by Y
- (N – Y) is divisible by X
Enter: X = 18, Y = 42
Enter: X = 100, Y = 200
Strategy: The issue may be solved primarily based on the next concept:
We are able to implement the easy math idea of the quantity system.
- N + X = Y …………(i)
- N – Y = X …………(ii)
Normalizes the equation we will get N could also be equal to (X*Y – X + Y). Additionally, it’s satisfying these two circumstances. So, the reply is (X * Y – X + Y).
Beneath is the implementation of the above strategy:
Time Complexity: O(1)
Auxiliary Area: O(1)