#K54262. Divisible Pair Sums

    ID: 29715 Type: Default 1000ms 256MiB

Divisible Pair Sums

Divisible Pair Sums

You are given an array \(B\) of \(N\) integers and an integer \(K\). Your task is to count the number of pairs of indices \((i, j)\) such that \(1 \leq i < j \leq N\) and

\( (B_i + B_j) \bmod K = 0 \)

For each test case, compute the number of valid pairs. This problem will test your ability to iterate over arrays and work with modular arithmetic.

Example:

Input:
2
5 3
1 2 3 4 5
4 2
2 4 6 8

Output: 4 6

</p>

inputFormat

The input is read from standard input (stdin) and is structured as follows:

  • The first line contains a single integer \(T\) denoting the number of test cases.
  • Each test case consists of two lines:
    • The first line contains two space-separated integers \(N\) and \(K\), where \(N\) is the number of elements in the array and \(K\) is the divisor.
    • The second line contains \(N\) space-separated integers representing the array \(B\).

outputFormat

For each test case, print a single integer on a new line representing the number of valid pairs \((i, j)\) such that \( (B_i + B_j) \bmod K = 0 \).

## sample
2
5 3
1 2 3 4 5
4 2
2 4 6 8
4

6

</p>