Cpp||Easy solution||O(n*n)
\nclass Solution {\npublic:\n    int numFactoredBinaryTrees(vector<int>& arr) {\n        int n=arr.size();\n        if(n==1)\n            return 1;\n        sor
```\nclass Solution {\npublic:\n    int numFactoredBinaryTrees(vector<int>& arr) {\n        int n=arr.size();\n        if(n==1)\n            return 1;\n        sort(arr.begin(),arr.end());\n        map<int,long>m1;\n        for(int a:arr)\n        {\n            m1[a]=1;\n        }\n        for(int i=0;i<n;i++)\n        {\n            for(int j=0;j<n;j++)\n            {\n                if(arr[i]%arr[j]==0)\n                {\n                    int r=arr[i]/arr[j];\n                    if(m1[r]>0)\n                    {\n                        m1[arr[i]]+=m1[arr[j]]*m1[r];\n                    }\n                }\n            }\n        }\n        long  int sum=0;\n        for(auto it:m1)\n        {\n            sum+=it.second;\n        }\n        return int(sum%1000000007);\n    }\n};\n```
['Dynamic Programming']