Description
Given a 0-indexed integer array nums 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:
4 valid pairs.
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:
All elements are 5, so all pairs have equal values. Pairs: (0,1) with 0*1%3=0, (0,2) with 0*2%3=0, (1,2) with 1*2%3=2. Only pairs (0,1) and (0,2) satisfy the divisibility condition. Count: 2.
Constraints
- •
1 ≤ nums.length ≤ 100