#706
Unrated
Farmer John's Favorite Operation
시간 제한
2s
메모리 제한
1024MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

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 aa of NN (1N21051 \leq N \leq 2 \cdot 10^5) non-negative integers and an integer MM (1M1091 \leq M \leq 10^9). Then, FJ will ask Bessie for an integer xx. In one operation, FJ can pick an index ii and subtract or add 11 to aia_i. FJ's boredom value is the minimum number of operations he must perform so that aixa_i-x is divisible by MM for all 1iN1 \leq i \leq N.

Among all possible xx, output FJ's minimum possible boredom value.

입력

The first line contains TT (1T101 \leq T \leq 10), the number of independent test cases to solve.

The first line of each test case contains NN and MM.

The second line of each test case contains a1,a2,...,aNa_1, a_2, ..., a_N (0ai1090 \leq a_i \leq 10^9).

It is guaranteed that the sum of NN over all test cases does not exceed 51055 \cdot 10^5.

출력

For each test case, output an integer on a new line containing FJ's minimum possible boredom value among all possible values of xx.

예제 입력 1

2
5 9
15 12 18 3 8
3 69
1 988244353 998244853

예제 출력 1

10
21

점수

Input 2: N1000N \le 1000 and M1000M \le 1000.Input 3: N1000N\le 1000.Inputs 4-5: M105M\le 10^5.Inputs 6-16: No additional constraints.

코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Unrated0명 투표
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.