Skip to content

Practice Number of Ways Where Square of Number Is Equal to Product of Two Numbers

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#1577
LeetCode Problem

Number of Ways Where Square of Number Is Equal to Product of Two Numbers

Problem Statement

Count both kinds of index triples: nums1[i]^2 = nums2[j] * nums2[k] with j < k, and nums2[i]^2 = nums1[j] * nums1[k] with j < k. All indices must be valid in their respective arrays. Equal values at different positions remain different index choices.

Source: Number of Ways Where Square of Number Is Equal to Product of Two Numbers on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums1 = [7,4], nums2 = [5,2,8,9]
Output
1

# Example 2

Input
nums1 = [1,1], nums2 = [1,1,1]
Output
9

# Example 3

Input
nums1 = [7,7,8,3], nums2 = [1,2,9,7]
Output
2

Constraints

1 <= nums1.length, nums2.length <= 1000
1 <= nums1[i], nums2[i] <= 10^5

Related LeetCode Problems

Practice more problems similar to Number of Ways Where Square of Number Is Equal to Product of Two Numbers.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.