python 3 | recursion + memoization | O(n^2)/O(n)
```\nclass Solution:\n    def numFactoredBinaryTrees(self, nums: List[int]) -> int:\n        nums = set(nums)\n        n = len(nums)\n        \n        @lru_cac
```\nclass Solution:\n    def numFactoredBinaryTrees(self, nums: List[int]) -> int:\n        nums = set(nums)\n        n = len(nums)\n        \n        @lru_cache(None)\n        def helper(num):\n            trees = 1\n            for factor in nums:\n                if not num % factor and num // factor in nums:\n                    trees += helper(factor) * helper(num // factor)\n\n            return trees\n        \n        return sum(helper(num) for num in nums) % (10 ** 9 + 7)
['Dynamic Programming', 'Recursion', 'Memoization', 'Python', 'Python3']