[C++] 30s. Faster than 100%
Sort first, and then check whether the 3 numbers can exist accoriding to the condition. For this purpose, we can use a HashMap to expedite the search. Thus, in 
Sort first, and then check whether the 3 numbers can exist accoriding to the condition. For this purpose, we can use a HashMap to expedite the search. Thus, in the beginning, we insert the elements into the HashMap (in C++ ```unordered_map```) and then check for the obvious relationship of ```nums1[i]^2 = nums2[j] * nums2[k]``` . We can increment the count by using the HashMap counts to make it even faster for the cases such as ```nums1 = [1,1,1,1]``` and ```nums2 = [1,1]```.\n```\nclass Solution {\npublic:\n    int numTriplets(vector<int>& nums1, vector<int>& nums2) {\n        sort(nums1.begin(),nums1.end());\n        sort(nums2.begin(),nums2.end());\n        long count = 0;\n        unordered_map<int,int> mp1;\n        unordered_map<int,int> mp2;\n        long num;\n        for (int i = 0;i<nums1.size();i++){\n            mp1[nums1[i]]++;\n        }\n        for (int i = 0;i<nums2.size();i++){\n            mp2[nums2[i]]++;\n        }\n        for (int i = 0;i<nums1.size();i++){\n            if (i>0 && nums1[i]==nums1[i-1]){\n                continue;\n            }\n            if (nums1[i]>nums2.back()){\n                break;\n            }\n            if (nums1[i]<nums2[0]){\n                continue;\n            }\n            num = (long)nums1[i]*nums1[i];\n            for (int j = 0;j<nums2.size();j++){\n                if (j>0 && nums2[j]==nums2[j-1]){\n                    continue;\n                }\n                if (num/nums2[j]<nums2[0])\n                    break;\n                if (num%nums2[j]==0 && num/nums2[j]>=nums2[j] && mp2.find(num/nums2[j])!=mp2.end()){\n                    if (num/nums2[j]==nums2[j]){\n                        count += mp1[nums1[i]]*(long)(mp2[nums2[j]]*(mp2[nums2[j]]-1))/2;\n                        break;\n                    }else{\n                        count += mp1[nums1[i]]*(long)mp2[nums2[j]]*mp2[num/nums2[j]];\n                    }\n                }\n            }\n        }\n        // cout<<"--------------------"<<endl;\n        for (int i = 0;i<nums2.size();i++){\n            if (i>0 && nums2[i]==nums2[i-1]){\n                continue;\n            }\n            if (nums2[i]>nums1.back()){\n                break;\n            }\n            if (nums2[i]<nums1[0]){\n                continue;\n            }\n            num = (long)nums2[i]*nums2[i];\n            for (int j = 0;j<nums1.size();j++){\n                if (j>0 && nums1[j]==nums1[j-1]){\n                    continue;\n                }\n                if (num/nums1[j]<nums1[0])\n                    break;\n                if (num%nums1[j]==0 && num/nums1[j]>=nums1[j] && mp1.find(num/nums1[j])!=mp1.end()){\n                    if (num/nums1[j]==nums1[j]){\n                        count += mp2[nums2[i]]*(long)(mp1[nums1[j]]*(mp1[nums1[j]]-1))/2;\n                        break;\n                    }else{\n                        count += mp2[nums2[i]]*(long)mp1[nums1[j]]*mp1[num/nums1[j]];\n                    }\n                }\n            }\n        }\n        return count;\n    }\n    \n};
[]