Java  O(n * sqrt(n)) solution using prime factorisation
Take the example \nnums1 -> [4]\nnums2 -> [2,2,2,4,4,8,8]\nfor the SqrNo = 16, possible 2 pairs of factors are (1,16) (2,8) (4,4)\nHave a count hashmap of all c
Take the example \nnums1 -> [4]\nnums2 -> [2,2,2,4,4,8,8]\nfor the SqrNo = 16, possible 2 pairs of factors are (1,16) (2,8) (4,4)\nHave a count hashmap of all count nos and simply check for all these cases. Repeat the same for each of nums2 combination against num1. One edge case is int overflow if n= 10^5 n ^ 2 will cause overflow, so use long type\nTime Complexity O(n * sqrt(n) + m * sqrt(m)) where n and m are sizes of num1 and num2 respectively.\n```\npublic int numTriplets(int[] nums1, int[] nums2) {\n        HashMap<Long, Integer> nums1Count = new HashMap<>();\n        HashMap<Long, Integer> nums2Count = new HashMap<>();\n        for (int n : nums1) {\n            nums1Count.put((long) n, nums1Count.getOrDefault((long) n, 0) + 1);\n        }\n        for (int n : nums2) {\n            nums2Count.put((long) n, nums2Count.getOrDefault((long) n, 0) + 1);\n        }\n        int res = 0;\n        for (int n : nums1) {\n            long sqr = (long) n * n;\n            res += findPairs(sqr, nums2Count);\n        }\n        for (int n : nums2) {\n            long sqr = (long) n * n;\n            res += findPairs(sqr, nums1Count);\n        }\n        return res;\n    }\n\n    private int findPairs(long sqrNumber, HashMap<Long, Integer> map) {\n        int count = 0;\n        for (long i = 1; i * i <= sqrNumber; i++) {\n            if (sqrNumber % i == 0 && map.containsKey(i) && map.containsKey(sqrNumber / i)) {\n                if (i == sqrNumber / i) {\n                    //sqr no ==> 16. array elements => 4,4,4,4 pairs ==> (3+2+1) sum of n numbers (n * (n+1))/2\n                    int totalVal = map.get(i) - 1;\n                    count += ((totalVal * (totalVal + 1)) / 2);\n                } else {\n                    //sqrNo ==> 16, combination=2*8  array elements => 2,2,8,8,8 => totalPairs => 2 * 3\n                    int multiplicandCount = map.get(i);\n                    int multiplierCount = map.get(sqrNumber / i);\n                    count += (multiplicandCount * multiplierCount);\n                }\n            }\n        }\n        return count;\n    }\n\n```
[]