#K51317. Count Pairs with Sum Divisible by K

    ID: 29061 Type: Default 1000ms 256MiB

Count Pairs with Sum Divisible by K

Count Pairs with Sum Divisible by K

You are given an array of N integers and an integer K. Your task is to find the number of pairs (i, j) such that:

  • \(1 \le i < j \le N\)
  • \( (a_i + a_j) \) is divisible by \(K\), i.e., \(a_i + a_j \equiv 0 \pmod{K}\)

For each test case, output the number of such valid pairs.

Note: The input involves multiple test cases. Read from stdin and print the output to stdout.

inputFormat

The first line contains an integer T representing the number of test cases. Each test case consists of two lines:

  1. The first line contains two integers N and K, where N is the number of array elements and K is the divisor.
  2. The second line contains N space-separated integers which form the array.

Constraints (if any): You may assume that K is a positive integer and N is at least 1.

outputFormat

For each test case, output a single integer on a new line representing the number of pairs (i, j) such that \(a_i + a_j\) is divisible by \(K\).

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

15

</p>