# Codeforces Round #653 (Div. 3) D. Zero Remainder Array

You are given an array a consisting of n positive integers.

Initially, you have an integer x=0. During one move, you can do one of the following two operations:

1. Choose exactly one i from 1 to n and increase ai by x (ai:=ai+x), then increase x by 1 (x:=x+1).
2. Just increase x by 1 (x:=x+1).

The first operation can be applied no more than once to each i from 1 to n.

Your task is to find the minimum number of moves required to obtain such an array that each its element is divisible by k (the value k is given).

You have to answer t independent test cases.

## Input

The first line of the input contains one integer t (1≤t≤2e4) — the number of test cases. Then t test cases follow.

The first line of the test case contains two integers n and k (1≤n≤2e5;1≤k≤1e9) — the length of a and the required divisior. The second line of the test case contains n integers a1,a2,…,an (1≤ai≤1e9), where ai is the i-th element of a.

It is guaranteed that the sum of n does not exceed 2e5 (∑n≤2e5).

## Output

For each test case, print the answer — the minimum number of moves required to obtain such an array that each its element is divisible by k.

## Example

### input

5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8


### output

6
18
0
227
8


1.因为最后答案要加一，若原始数组所有数模 $k$ 都已为 0，此时答案就为 0，所以 $ans$ 初始值设为 -1
2.会爆 int
AC代码如下：

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
int n,t,k;
scanf("%d",&t);
while(t--){
scanf("%d%d",&n,&k);
ll x,ans=-1;
map<ll,ll>m;
for(int i=0;i<n;i++){
scanf("%lld",&x);
if(x%k) ans=max(ans,k-x%k+k*m[k-x%k]++);
}
printf("%lld\n",ans+1);
}
}


07-10

06-29 104

06-29 74

06-29 94

06-29 3957

06-29 245

10-04 725

07-06 61

06-29 117

05-14 170

08-09 785

04-17 1052

10-13 627

02-09 161

06-19 74

11-07 1393

#### Python可以这样学（第一季：Python内功修炼）

02-23
©️2020 CSDN 皮肤主题: 像素格子 设计师: CSDN官方博客

1.余额是钱包充值的虚拟货币，按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载，可以购买VIP、C币套餐、付费专栏及课程。