😎Python 3. As short as it gets. O(n^2) 98% Time 90% Memory.
This is as short as I could get my code: \n\nclass Solution:\n    def numFactoredBinaryTrees(self, arr: List[int]) -> int:\n        mod = 1000 * 1000 * 1000 + 7
This is as short as I could get my code: \n```\nclass Solution:\n    def numFactoredBinaryTrees(self, arr: List[int]) -> int:\n        mod = 1000 * 1000 * 1000 + 7\n        arr =sorted(arr)\n        dp = {a:1 for a in arr}\n            \n        for i,a in enumerate(arr):\n            for j in range(i):\n                b, c = arr[j], a//arr[j]\n                if c < b:\n                    break\n                if a % b != 0 or c not in dp:\n                    continue\n                add = dp[b] * dp[c]\n                dp[a] += add if b == c else 2 * add\n            dp[a] = dp[a] % mod\n        return sum(dp.values()) % mod\n```
['Dynamic Programming']