Tuple with Same Product
Given an array nums of distinct positive integers, return the number of tuples (a, b, c, d) such that a * b = c * d where a, b, c, and d are elements of nums, and a != b != c != d.
Example 1
Input
nums = [2,3,4,6]Output
8There are 8 valid tuples formed by the pairs
(2, 6) and (3, 4) because they have the same product.Example 2
Input
nums = [1,2,4,5,10]Output
16There are 16 valid tuples formed by matching equal-product pairs such as
(1, 10) with (2, 5) and (2, 10) with (4, 5).Constraints
- 1 <= nums.length <= 1000
- 1 <= nums[i] <= 10^4
- All elements in
numsare distinct.