Given a 0-indexed integer array nums of length n and an integer k, return the number of pairs (i, j) with 0 <= i < j < n such that nums[i] == nums[j] and i * j is divisible by k.
Given a 0-indexed integer array nums of length n and an integer k, return the number of pairs (i, j) with 0 <= i < j < n such that nums[i] == nums[j] and i * j is divisible by k.
Example 1:
Input: {"nums":[3,1,2,2,2,1,3],"k":2}
Output: 4
Constraints:
1≤nums.length≤100
1≤nums[i],k≤100
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"nums":[3,1,2,2,2,1,3],"k":2}
Only equal values can pair, so group indices by value. For each new index j, test it against the earlier indices in its own group: the pair counts when i * j is a multiple of 2.