1726. Tuple with Same Product Medium
1/**
2 * [1726] Tuple with Same Product
3 *
4 * 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.
5 *
6 * Example 1:
7 *
8 * Input: nums = [2,3,4,6]
9 * Output: 8
10 * Explanation: There are 8 valid tuples:
11 * (2,6,3,4) , (2,6,4,3) , (6,2,3,4) , (6,2,4,3)
12 * (3,4,2,6) , (4,3,2,6) , (3,4,6,2) , (4,3,6,2)
13 *
14 * Example 2:
15 *
16 * Input: nums = [1,2,4,5,10]
17 * Output: 16
18 * Explanation: There are 16 valid tuples:
19 * (1,10,2,5) , (1,10,5,2) , (10,1,2,5) , (10,1,5,2)
20 * (2,5,1,10) , (2,5,10,1) , (5,2,1,10) , (5,2,10,1)
21 * (2,10,4,5) , (2,10,5,4) , (10,2,4,5) , (10,2,5,4)
22 * (4,5,2,10) , (4,5,10,2) , (5,4,2,10) , (5,4,10,2)
23 *
24 *
25 * Constraints:
26 *
27 * 1 <= nums.length <= 1000
28 * 1 <= nums[i] <= 10^4
29 * All elements in nums are distinct.
30 *
31 */
32pub struct Solution {}
33
34// problem: https://leetcode.com/problems/tuple-with-same-product/
35// discuss: https://leetcode.com/problems/tuple-with-same-product/discuss/?currentPage=1&orderBy=most_votes&query=
36
37// submission codes start here
38
39impl Solution {
40 pub fn tuple_same_product(nums: Vec<i32>) -> i32 {
41 0
42 }
43}
44
45// submission codes end
46
47#[cfg(test)]
48mod tests {
49 use super::*;
50
51 #[test]
52 fn test_1726() {
53 }
54}
55
Back
© 2025 bowen.ge All Rights Reserved.