97.50% Optimized DP
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nconst int MOD = 1e9 + 7;\n\nclass Solution {\npublic:\n    int numFactoredBinaryTrees(std::vector<int>& arr) {\n            std::sort(arr.begin(), arr.end());\n                    std::unordered_set<int> s(arr.begin(), arr.end());\n                            std::unordered_map<int, int> dp;\n                                    for (int x : arr) dp[x] = 1;\n                                            \n                                                    for (int i : arr) {\n                                                                for (int j : arr) {\n                                                                                if (j > std::sqrt(i)) break;\n                                                                                                if (i % j == 0 && s.find(i / j) != s.end()) {\n                                                                                                                    long long temp = (long long)dp[j] * dp[i / j];\n                                                                                                                                        if (i / j == j) {\n                                                                                                                                                                dp[i] = (dp[i] + temp) % MOD;\n                                                                                                                                                                                    } else {\n                                                                                                                                                                                                            dp[i] = (dp[i] + temp * 2) % MOD;\n                                                                                                                                                                                                                                }\n                                                                                                                                                                                                                                                }\n                                                                                                                                                                                                                                                            }\n                                                                                                                                                                                                                                                                    }\n                                                                                                                                                                                                                                                                            \n                                                                                                                                                                                                                                                                                    int result = 0;\n                                                                                                                                                                                                                                                                                            for (auto& [_, val] : dp) {\n                                                                                                                                                                                                                                                                                                        result = (result + val) % MOD;\n                                                                                                                                                                                                                                                                                                                }\n                                                                                                                                                                                                                                                                                                                        return result;\n                                                                                                                                                                                                                                                                                                                            }\n                                                                                                                                                                                                                                                                                                                            };\n\n\n\n\n\n```
['C++']