Short & Simple. O(n^2 + m^2)
\npublic class Solution {\n\n    int c(int[] a, int[] b)\n    {\n        int res = 0;\n        var aa = a.Select(x => (long)x * (long)x).GroupBy(x => x).ToDicti
\npublic class Solution {\n\n    int c(int[] a, int[] b)\n    {\n        int res = 0;\n        var aa = a.Select(x => (long)x * (long)x).GroupBy(x => x).ToDictionary(x => x.Key, x => x.Count());\n        for (int i = 0; i < b.Length; i++)\n            for (int k = i + 1; k < b.Length; k++)\n                if (aa.ContainsKey((long)b[i] * b[k]))\n                    res += aa[(long)b[i] * b[k]];\n        return res;\n    }\n\n    public int NumTriplets(int[] nums1, int[] nums2) {\n        return c(nums1, nums2) + c(nums2, nums1);\n    }\n}\n```
['C#']