[C++] [100% faster] [95% space efficient] Easy and direct solution using unordered_map
\nclass Solution {\npublic:\n    int numFactoredBinaryTrees(vector<int>& arr) {\n        int size_ = arr.size();\n        unordered_map<int, unsigned long long>
```\nclass Solution {\npublic:\n    int numFactoredBinaryTrees(vector<int>& arr) {\n        int size_ = arr.size();\n        unordered_map<int, unsigned long long> umap_;\n        int total = 0;\n        int MOD = 1000000007;\n        sort(arr.begin(), arr.end());\n        for (int i = 0; i < size_; i++) {\n            int curr = arr[i];\n            umap_[curr] = 1;\n            for (int j = 0; j < i; j++) {\n                if (arr[i]%arr[j] == 0) {\n                    int a = arr[j];\n                    int b = arr[i]/arr[j];\n                    if (a > b) {\n                        break;\n                    }\n                    else if (a == b) {\n                        umap_[curr] += umap_[a]*umap_[a];\n                    }\n                    else if (umap_.count(b)) {\n                        umap_[curr] += 2*umap_[a]*umap_[b];\n                    }\n                }\n            }\n            total = (total + umap_[curr])%MOD;\n        }\n        return total;\n    }\n};\n```
[]