Beats 100% Other's Solutions
\nclass Solution:\n    def numFactoredBinaryTrees(self, A: List[int]) -> int:\n                    A.sort()\n                    fmap, ans = defaultdict(), 0\n 
```\nclass Solution:\n    def numFactoredBinaryTrees(self, A: List[int]) -> int:\n                    A.sort()\n                    fmap, ans = defaultdict(), 0\n                    for num in A:\n                        ways, lim = 1, sqrt(num)\n                        for fA in A:\n                            if fA > lim: break\n                            fB = num / fA\n                            if fB in fmap:\n                                ways += fmap[fA] * fmap[fB] * (1 if fA == fB else 2)\n                        fmap[num], ans = ways, (ans + ways)\n                    return ans % 1000000007\n            \n```
['Tree']