Chef has an arrayof length .
Since Chef’s favorite number is, he wants to make all numbers in the array a multiple of .
Chef can do the following operation:
- Select any different indices and and increase by and decrease by .
Help Chef find out the minimum number of operations required (or report its not possible) to achieve his objective.
Make it Divisible solution codechef – Input Format
- The first line will contain , the number of test cases. Then the test cases follow.
- The first line of each test case contains , denoting the length of the array.
- The second line of each testcase contains space separated integers .
Output the minimum number of operations required to make all numbers divisible by.
If it is not possible to make every number divisible by, then output .
Make it Divisible solution codechef – Constraints
- Sum of over all test cases does not exceed
Sample Input 1
3 3 1 2 3 4 6 3 9 12 2 4 3
Sample Output 1
1 0 -1
Explanation Make it Divisible solution codechef
Test Case: Chef can select the indices and and thus increase by and decrease by . Thus the array becomes . So every number is now divisible by .
Test Case: Since all the numbers are already multiples of , Chef will not need to apply the operation at all.
Test Case: There is no way to make all the numbers a multiple of .