Problem of the day
‘N’ = 5, ‘K’ = 4, ‘nums’ = [2, 6, 1, 7, 8]
Output: 5
Explanation: (1, 2), (1, 5), (2, 5), (3, 5), and (4, 5) pairs have their products divisible by K.
The first line will contain the integer 'T', the number of test cases.
Each test case consists of two lines.
The first input line contains two integers, 'N' and 'K', separated by spaces.
Followed by a line containing space-separated ‘N’ positive integers, denoting the array nums.
For each test case, print the count of unique pairs having their product divisible by ‘K’.
You don't need to print anything. It has already been taken care of. Just implement the given function.
1 <= 'T' <= 10
1 <= 'N' <= 10^5
1 <= 'K' <= 10^5
1 <= ‘nums[i]’ <= 10^6
It is guaranteed that sum of ‘N’ over all test cases is <= 10^5
Time Limit: 1 sec
2
4 5
1 2 3 4
5 2
1 2 3 4 5
0
7
For the first test case, there is no pair of indices whose corresponding product is divisible by 5.
For the second test case, the seven pairs of indices whose corresponding products are divisible by two are
(1, 2), (1, 4), (2, 3), (2, 4), (2, 5), (3, 4), and (4, 5).
Their products are 2, 4, 6, 8, 10, 12, and 20 respectively.
Other pairs such as (1, 3) and (3, 5) have products 3 and 15, respectively, which are not divisible by 2.
2
7 3
3 2 6 1 8 4 1
9 6
8 10 2 5 9 6 3 8 2
11
18