#K44687. Count Divisible Pairs

    ID: 27587 Type: Default 1000ms 256MiB

Count Divisible Pairs

Count Divisible Pairs

You are given an integer n representing the number of elements in an array, an integer k, and an array of n integers. Your task is to count the number of pairs (i, j) (with i < j) such that the sum of array[i] and array[j] is divisible by k. In other words, you need to find the number of pairs for which

\( (array[i] + array[j]) \mod k = 0 \)

The input is provided on stdin and the output should be printed to stdout as a single integer representing the number of valid pairs.

inputFormat

The first line of input contains two integers n and k separated by a space.

The second line contains n space-separated integers representing the elements of the array.

Example:

5 3
1 2 3 4 5

outputFormat

Print a single integer to stdout which is the number of pairs (i, j) (with i < j) such that (array[i] + array[j]) is divisible by k.

Example:

4
## sample
5 3
1 2 3 4 5
4