Python Solution Based on Binary Search And Memorization
Time Complexity = O ( N * N * Log N )\n\n\n\nclass Solution:\n    def numTriplets(self, nums1: List[int], nums2: List[int]) -> int:      \n        nums1.sort()\
Time Complexity = O ( N * N * Log N )\n\n\n```\nclass Solution:\n    def numTriplets(self, nums1: List[int], nums2: List[int]) -> int:      \n        nums1.sort()\n        nums2.sort()\n        \n        def lowerbound(target, left, right, nums):\n            while left < right:\n                mid = left + (right - left) // 2\n\n                if nums[mid] == target:\n                    right = mid\n                elif nums[mid] < target:\n                    left = mid + 1\n                else:\n                    right = mid\n            \n            return left\n        \n        def higherbound(target, left, right, nums):\n            while left < right:\n                mid = left + (right - left) // 2\n                \n                if nums[mid] == target:\n                    left = mid + 1\n                elif nums[mid] < target:\n                    left = mid + 1\n                else:\n                    right = mid\n            \n            return left\n            \n    \n        def helper(n, nums, memo):\n            if n in memo:\n                return memo[n]\n            \n            result = 0\n            \n            for i in range(len(nums)):\n                if n % nums[i] != 0:\n                    continue\n                    \n                target = n // nums[i]\n                \n                # find total number of target in nums[i+1:]\n                lower = lowerbound(target, i+1, len(nums), nums)\n                higher = higherbound(target, i+1, len(nums), nums)\n                \n                result += (higher - lower)\n            \n            memo[n] = result\n            return result\n        \n        result = 0\n        \n        memo1 = {}\n        for n in nums1:\n            result += helper(n*n, nums2, memo1)\n        \n        memo2 = {}\n        for n in nums2:\n            result += helper(n*n, nums1, memo2)\n        \n        return result\n\n```
['Memoization', 'Binary Tree', 'Python', 'Python3']