#C9698. Count Divisible Pairs

    ID: 53819 Type: Default 1000ms 256MiB

Count Divisible Pairs

Count Divisible Pairs

Given an array of integers (nums) and an integer (k), your task is to count the number of pairs ((i, j)) where (i < j) such that the sum (nums[i] + nums[j]) is divisible by (k). In other words, you need to find the number of pairs for which ( (nums[i] + nums[j]) \mod k = 0 ).

Example: If (nums = [1, 2, 3, 4, 5]) and (k = 3), the valid pairs are those whose sums are divisible by 3, and the answer is 4.

inputFormat

The first line contains two 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 (nums).

outputFormat

Output a single integer, the number of pairs ((i, j)) with (i < j) such that ( (nums[i] + nums[j]) \mod k = 0 ).## sample

5 3
1 2 3 4 5
4

</p>