ACM ICPC Is Coming

5

1 votes
Implementaion, Simple-math, Hashing
Problem

ACM ICPC is approaching and we urge you to participate in it. Try to solve the given problem.

Given an array A with N elements, find the number of pairs, (A[i], A[j]) where i < j, whose absolute difference is K and sum is divisible by K

Input Format

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

Each test case is as follows:

The first line contains two space seperated integers, N (the number of elements in the array A) and K.

Second line has N space seperated numbers, Ai.

Output Format

For each testcase, print a single line containing the number of distinct pairs satisfying the given criteria.

Constraints

1 <= <= 10

2 <= <= 105

1 <= K <= 109

1 <= Ai <= 109, where i ∈ [0,n)

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

Pair 1 : (1,3) - |1-3| = 2 & (1+3) is divisible by 2.

Pair 2 : (3,5) - |3-5| = 2 & (3+5) is divisible by 2.

Pair 3 : (5,7) - |5-7| = 2 & (5+7) is divisible by 2.

Editor Image

?