#K95897. Unique Pair Sum

    ID: 38965 Type: Default 1000ms 256MiB

Unique Pair Sum

Unique Pair Sum

You are given an array of integers and an integer target value. Your task is to determine the number of unique pairs (a, b) in the array such that a + b = target. A pair is considered unique if no other pair contains the same two numbers regardless of order.

Note: Even if the same number appears multiple times in the array, each distinct pair is counted only once.

The formula to calculate the condition can be written in LaTeX as follows:

\( a+b = \text{target} \)

You must process multiple test cases. For each test case, the input contains the number of elements in the array, the target sum and the list of integers. Output the result for each test case on a new line.

inputFormat

The first line contains an integer T, the number of test cases.

For each test case, the first line contains two integers N and K where N is the number of elements in the array and K is the target sum. The second line contains N integers, representing the array elements.

Example:

6
4 6
1 5 7 -1
3 50
10 20 30
3 2
1 1 1
4 5
1 2 3 4
4 -5
-1 -2 -3 -4
4 1
-1 -9 -5 10

outputFormat

For each test case, output a single line containing the number of unique pairs that sum up to the target K.

Corresponding to the above example, the output should be:

2
1
1
2
2
1
## sample
6
4 6
1 5 7 -1
3 50
10 20 30
3 2
1 1 1
4 5
1 2 3 4
4 -5
-1 -2 -3 -4
4 1
-1 -9 -5 10
2

1 1 2 2 1

</p>