countTriplets that takes two arrays A and B as input.B.a in array A:
a. Calculate the target square t as a * a.
b. Iterate over the frequency map of B:
i. If t is divisible by b and t / b is in the map, increment the counter by the product of their frequencies.
ii. If b is the square root of t, increment the counter by the combination count cnt * (cnt - 1) / 2.countTriplets(nums1, nums2) and countTriplets(nums2, nums1).