Farmer John's Favorite Operation
시간 제한2초메모리 제한2048 MB
배열과 정수 M이 주어질 때, 모든 a_i가 M으로 나눈 나머지가 x와 같아지도록 만드는 최소 연산 횟수를 구한다.
문제
It is another cold and boring day on Farmer John's farm. To pass the time, Farmer John has invented a fun leisure activity involving performing operations on an integer array.
Farmer John has an array of () non-negative integers and an integer (). Then, FJ will ask Bessie for an integer . In one operation, FJ can pick an index and subtract or add to . FJ's boredom value is the minimum number of operations he must perform so that is divisible by for all .
Among all possible , output FJ's minimum possible boredom value.
입력
The first line contains (), the number of independent test cases to solve.
The first line of each test case contains and .
The second line of each test case contains ().
It is guaranteed that the sum of over all test cases does not exceed .
출력
For each test case, output an integer on a new line containing FJ's minimum possible boredom value among all possible values of .