1577. Number of Ways Where Square of Number Is Equal to Product of Two Numbers Medium
1/**
2 * [1577] Number of Ways Where Square of Number Is Equal to Product of Two Numbers
3 *
4 * Given two arrays of integers nums1 and nums2, return the number of triplets formed (type 1 and type 2) under the following rules:
5 *
6 * Type 1: Triplet (i, j, k) if nums1[i]^2 == nums2[j] * nums2[k] where 0 <= i < nums1.length and 0 <= j < k < nums2.length.
7 * Type 2: Triplet (i, j, k) if nums2[i]^2 == nums1[j] * nums1[k] where 0 <= i < nums2.length and 0 <= j < k < nums1.length.
8 *
9 *
10 * Example 1:
11 *
12 * Input: nums1 = [7,4], nums2 = [5,2,8,9]
13 * Output: 1
14 * Explanation: Type 1: (1, 1, 2), nums1[1]^2 = nums2[1] * nums2[2]. (4^2 = 2 * 8).
15 *
16 * Example 2:
17 *
18 * Input: nums1 = [1,1], nums2 = [1,1,1]
19 * Output: 9
20 * Explanation: All Triplets are valid, because 1^2 = 1 * 1.
21 * Type 1: (0,0,1), (0,0,2), (0,1,2), (1,0,1), (1,0,2), (1,1,2). nums1[i]^2 = nums2[j] * nums2[k].
22 * Type 2: (0,0,1), (1,0,1), (2,0,1). nums2[i]^2 = nums1[j] * nums1[k].
23 *
24 * Example 3:
25 *
26 * Input: nums1 = [7,7,8,3], nums2 = [1,2,9,7]
27 * Output: 2
28 * Explanation: There are 2 valid triplets.
29 * Type 1: (3,0,2). nums1[3]^2 = nums2[0] * nums2[2].
30 * Type 2: (3,0,1). nums2[3]^2 = nums1[0] * nums1[1].
31 *
32 *
33 * Constraints:
34 *
35 * 1 <= nums1.length, nums2.length <= 1000
36 * 1 <= nums1[i], nums2[i] <= 10^5
37 *
38 */
39pub struct Solution {}
40
41// problem: https://leetcode.com/problems/number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers/
42// discuss: https://leetcode.com/problems/number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers/discuss/?currentPage=1&orderBy=most_votes&query=
43
44// submission codes start here
45
46impl Solution {
47 pub fn num_triplets(nums1: Vec<i32>, nums2: Vec<i32>) -> i32 {
48 0
49 }
50}
51
52// submission codes end
53
54#[cfg(test)]
55mod tests {
56 use super::*;
57
58 #[test]
59 fn test_1577() {
60 }
61}
62
Back
© 2025 bowen.ge All Rights Reserved.