Description
Given a 0-indexed integer array nums of length n and an integer k, return the number of pairs (i, j) where 0 <= i < j < n, nums[i] == nums[j], and (i * j) is divisible by k.
Examples
Input:
nums = [3,1,2,2,2,1,3], k = 2Output:
4Explanation:
Valid pairs: (0,6),(2,3),(2,4),(3,4).
Input:
nums = [1,2,3,4], k = 1Output:
0Explanation:
All elements are distinct, so no pair (i, j) has nums[i] == nums[j]. The count is 0.
Input:
nums = [5,5,5], k = 3Output:
2Explanation:
Pairs must satisfy nums[i] == nums[j] and (i*j) % k == 0. All elements are 5, so checking divisibility: (0*1) % 3 = 0 (valid), (0*2) % 3 = 0 (valid), (1*2) % 3 = 2 (invalid). Valid pairs: (0,1) and (0,2).
Constraints
- •
1 ≤ nums.length ≤ 100