C++ || DP || Two Pointers || Easy understanding
\nclass Solution {\npublic:\n    const int mod = 1e9 + 7;\n    int numFactoredBinaryTrees(vector<int>& arr) {\n        int n = arr.size();\n        sort(arr.beg
```\nclass Solution {\npublic:\n    const int mod = 1e9 + 7;\n    int numFactoredBinaryTrees(vector<int>& arr) {\n        int n = arr.size();\n        sort(arr.begin(), arr.end());\n        vector<long> dp(n);\n        dp[0] = 1;\n        int res = 0;\n        for (int i = 1; i < n; i++)\n        {\n            int target = arr[i];\n            int p = 0, q = i - 1; \n            long ways = 1;\n            while(p <= q)\n            {\n                long mul = (((long)arr[p]) * (arr[q]));\n                if (mul == target) \n                {\n                    if (p == q) ways += (dp[p] * dp[q]) % mod;\n                    else ways += ((dp[p] * dp[q]) * 2) % mod;\n                    p++;\n                    q--;\n                }\n                else if (mul < target) p++;\n                else if (mul > target) q--;\n            }\n            dp[i] = ways;\n            res  = (int)((res + dp[i]) % mod);\n        }\n        return res + 1;\n    }\n};\n```
['Dynamic Programming', 'C']