Untitled
user_5668965
c_cpp
a year ago
768 B
11
Indexable
#include <bits/stdc++.h>
using i64 = long long;
void solve() {
int n, k;
std::cin >> n >> k;
std::vector<int> a(n);
for (int i = 0; i < n; i++) {
std::cin >> a[i];
}
int ans = k;
for (int i = 0; i < n; i++) {
ans = std::min(ans, (k - a[i] % k) % k);
}
if (k == 4) {
int even = std::count_if(a.begin(), a.end(),
[&](int x) {
return x % 2 == 0;
});
ans = std::min(ans, std::max(0, 2 - even));
}
std::cout << ans << "\n";
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t;
std::cin >> t;
while (t--) {
solve();
}
return 0;
}Editor is loading...
Leave a Comment