#include <iostream>
#include <vector>
using namespace std;
struct Pair {
using num_t = long;
using sum_t = long long;
num_t a;
num_t b;
bool matches(const sum_t k) const {
return (sum_t)a + (sum_t)b == k;
}
};
class Task {
public:
Task(const vector<Pair::num_t>& present) {
const size_t n = present.size();
const auto m = n - 1;
for (size_t i = 0; i < m; ++i) {
for (size_t j = i + 1; j < n; ++j) {
pairs.emplace_back(Pair{ present[i], present[j] });
}
}
}
size_t count(const Pair::sum_t k) const {
size_t quantity = 0;
for (const auto& item : pairs) {
if (item.matches(k)) {
++quantity;
}
}
return quantity;
}
private:
vector<Pair> pairs;
};
int main() {
size_t i = 0, t;
cin >> t;
vector<size_t> results(t);
while (i < t) {
size_t n;
cin >> n;
Pair::sum_t k;
cin >> k;
vector<Pair::num_t> present(n);
for (auto& number : present) cin >> number;
Task task(present);
results[i] = task.count(k);
++i;
}
for (auto result : results) {
cout << result << '\n';
}
}
#include <iostream>
#include <unordered_map>
int countPairsWithSumK(int arr[], int N, int K) {
std::unordered_map<int, int> countMap;
int pairCount = 0;
for (int i = 0; i < N; i++) {
int complement = K - arr[i];
if (countMap.find(complement)!= countMap.end()) {
pairCount += countMap[complement];
}
countMap[arr[i]]++;
}
return pairCount;
}
int main() {
int arr[] = {1, 5, 7, 1, 9, 5};
int N = sizeof(arr) / sizeof(arr[0]);
int K = 10;
int result = countPairsWithSumK(arr, N, K);
std::cout << "Количество пар с суммой " << K << ": " << result << std::endl;
return 0;
}