Computer Science, asked by mynk2331, 1 day ago

You are an active user of the online education platform - XYZ. You have done till now b submissions out of a have been correct. So, the current fraction is a / b.
But you like fraction x / y very much, tell us the no. of minimum submissions you need to do to reach your favorite fraction.
Note
• x and y will be co-primes
• If not possible then the answer will be -1
Sample Test Cases
2
[[1, 2, 4, 5],
[2, 5, 1, 2]]
Output: [3, 1]
Explanation:
For [1,2,4,5], Initially, we have 1 correct submission out of 2 total submissions. i.e the current fraction is 1/2. The desired fraction is 4/5. This can be achieved through 3 more correct submissions, which will help us get a total of 4 correct submissions out of 5, reaching the desired fraction of 4/5. Hence for [1,2,4,5] output is 3.
For [2,5,1,2] Initially, we have 2 correct submissions out of 5 total submissions. i.e the current fraction is 2/5. The desired fraction is 1/2. This can be achieved through 1 more correct submission, which will help us get a total of 3 correct submissions out of 6, i.e 3/6 = 1/2. Hence for [2,5,1,2] output is 1.
Constraints
1 <= t <= 1000
0 <= a <= b <= 109, b > 0
0 <= x <= y <= 109, y > 0
• [execution time limit] 3 seconds (java)
• [input] integer t
No. of test cases
• [input] array.array.integer tests
t x 4 matrix, each row consists of 4 nos., a, b, x, y
• [output] array.integer64
Minimum no. of submissions for each test case, array of t size
[Java] Syntax Tips
// Prints help message to the console
// Returns a string
//
// Globals declared here will cause a compilation error,
// declare variables inside the function instead!
String helloWorld(String name) {
System.out.println("This prints to the console when you Run Tests");
return "Hello, " + name;
}​

Answers

Answered by Anonymous
1

Answer:

Means I don't understand your

questions

Similar questions