Minimum Extra Chocolates
Given two boxes of chocolate containing A and B chocolates representing the number of chocolates Alex and Drake have, respectively. Drake is the younger child and will only be happy if he receives a multiple of what Alex gets. You decided to buy some extra chocolates.
Mathematically, The share of chocolates will be:
k * (A + X) = (B + Y) for some non-negative integer X and Y and some positive integer k.
What is the minimum number of extra chocolates (X + Y) that you need to buy?
Note: The original chocolates (A and B) cannot be transferred among each other.
Complete the function solution. The function takes 2 parameters and returns the solution:
A: Represents the number of initial chocolates in Alex's boxB: Represents the number of initial chocolates in Drake's box
Limits
Time Limit: 1.0 sec(s) for each input file
Memory Limit: 256 MB
Source Limit: 1024 KB
Scoring
Score is assigned if any testcase passes
Allowed Languages
[List of programming languages]
Note:
Your code must be able to print the sample output from the provided sample input. However, your code is run against multiple hidden test cases. Therefore, your code must pass these hidden test cases to solve the problem statement.
Constraints
0 < A,B < 10^9
⊹ ࣪ ﹏𓊝﹏𓂁﹏⊹ ࣪Endless thanks to spike!𓂃 𓈒𓏸
1Example 1
For the given test case, if you let X=0 and Y=0, then B+Y=16 will be a multiple of A+X=8. Here, you have X+Y=0, and there is no way to make X+Y smaller, so the answer is 0.
2Example 2
Adding 1 to A and 3 to B, we get A as 8 and B as 40, which satisfies the condition as k*A=B. k will be 5 here.
3Example 3
X will be 7 and Y will 2, k will end up becoming 3.
Constraints
Limits and guarantees your solution can rely on.
0 < A,B < 10^9