-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path1888B Raspberries.cpp
52 lines (48 loc) · 1.01 KB
/
1888B Raspberries.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
author : MishkatIT
created : Sunday 2023-10-22-17.38.20
*/
#include<bits/stdc++.h>
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using ll = long long;
using namespace std;
int main()
{
fio;
int t;
cin >> t;
while(t--) {
ll n, k;
cin >> n >> k;
vector<int>v(n);
for (int i = 0; i < n; i++) cin >> v[i];
ll mn = 1e9;
int two = 0;
if(k == 4) {
for (auto& i: v) {
while(i % 2 == 0) {
two++;
i /= 2;
}
}
if(two >= 2) {
mn = 0;
} else if(two == 1) {
mn = 1;
} else {
mn = 2;
}
}
ll m = 1;
for (auto & i: v) {
if(i % k == 0) {
mn = 0;
} else {
i %= k;
mn = min(mn, k - i);
}
}
cout << mn << '\n';
}
return 0;
}