Count Array Pairs Divisible by K
Given a 0-indexed integer array nums of length n and an integer k, return the number of pairs (i, j) such that:
0 <= i < j <= n - 1nums[i] * nums[j]is divisible byk.
Example 1
Input
nums = [1,2,3,4,5], k = 2Output
7The 7 pairs of indices whose corresponding products are divisible by 2 are (0, 1), (0, 3), (1, 2), (1, 3), (1, 4), (2, 3), and (3, 4).
Example 2
Input
nums = [1,2,3,4], k = 5Output
0There does not exist any pair of indices whose corresponding product is divisible by 5.
Constraints
- 1 <= nums.length <= 10^5
- 1 <= nums[i], k <= 10^5