Fastest python
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution(object):\n    def numFactoredBinaryTrees(self, arr):\n        mod = int(1e9 + 7)\n        arr.sort()\n        ans = 0\n        map = {}\n\n        for x in arr:\n            ways = 1\n            max_val = int(x ** 0.5)\n\n            j = 0\n            left = arr[0]\n            while left <= max_val:\n                if x % left != 0:\n                    j += 1\n                    left = arr[j]\n                    continue\n                right = x // left\n                if right in map:\n                    ways = (ways + map[left] * map[right] * (1 if left == right else 2)) % mod\n                j += 1\n                left = arr[j]\n            map[x] = ways\n            ans = (ans + ways) % mod\n\n        return ans\n        \n```
['Python']