write a java Problem Chef has � A marbles, and his friend has � B. They want to…
- User
write a java Problem Chef has � A marbles, and his friend has � B. They want to redistribute the marbles among themselves such that after redistributing:
Chef and his friend both have at least one marble each; and The number of marbles with Chef is divisible by the number of marbles with his friend. What's the minimum number of marbles that need to be transferred from one person to another to achieve this?
Input Format The first line of input will contain a single integer � T, denoting the number of test cases. The only line of each test case contains two space-separated integers � A and � B — the number of marbles with Chef and the number of marbles with his friend, respectively. Output Format For each test case, output on a new line the minimum number of marbles to be transferred. Constraints 1 ≤ � ≤ 1000 1≤T≤1000 1 ≤ � , � ≤ 1000 1≤A,B≤1000 Sample 1: Input Output 4 7 2 10 5 6 5 5 6 1 0 4 5 Explanation: Test case 1 1: Chef has 7 7 marbles and his friend has 2 2. He can give his friend one marble. Now he has 6 6 marbles, his friend has 3 3, and 6 6 is divisible by 3 3.
Test case 2 2: 10 10 is already divisible by 5 5, no need to redistribute any marbles.
Test case 3 3: Chef can take 4 4 marbles from his friend. Now, Chef has 10 10 marbles, and his friend has 1 1 marble.
Test case 4 4: Chef can take 5 5 marbles from his friend. Now, Chef has 10 10 marbles, and his friend has 1 1 marble.
accepted Accepted 2407 total-Submissions Submissions 18309 accuracy Accuracy 16.69 Did you like the problem statement? 51 users found this helpful
- Assistant
Yes, the problem statement is clear and easy to understand. It provides the required inputs and the expected output, and also includes a sample explanation.
- Assistant
Great! Here's a possible Java solution for the given problem:
java