Best C++ Solution || Beats 100%
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```\nclass Solution {   // coppied\npublic:\n    int numFactoredBinaryTrees(vector<int>& arr) {\n        if(arr.size() == 1) return 1;\n\n        /*\n        First, we need to sort the given array, and \n        create a hashmap to store how many binary trees \n        can be made with that integer as a root.\n        */\n\n        sort(arr.begin(), arr.end());\n        unordered_map<int, long long> mp;\n\n        /*\n        As we can make atleast one binary tree with each integer \n        with null nodes, we increase the value to 1 for \n        every integer in the map.\n        */\n\n        for(int i = 0; i<arr.size(); i++){\n            mp[arr[i]] = 1;\n        }\n\n        /*\n        Now, we need to find how many binary trees can be made \n        with each integer as a root, \n        and we can find that by multiplying the number of trees \n        that can be formed from their children as roots.\n        We leave the first integer because it can\'t have any \n        children because it is the smallest in the array. \n\n        Now, we have to find the children nodes, and add the \n        product of the children values to the hashmap.\n        */\n\n        for(int i = 1; i<arr.size(); i++){\n            for(int j = 0; j<i && arr[j]<=sqrt(arr[i]); j++){\n                if(arr[i] % arr[j] == 0 && mp.find(arr[i]/arr[j]) != mp.end()){\n                    if(arr[i]/arr[j] == arr[j]){\n                        mp[arr[i]] += (mp[arr[j]] * mp[arr[i]/arr[j]]); \n                    }\n                    else{\n                        mp[arr[i]] += (mp[arr[j]] * mp[arr[i]/arr[j]]) * 2; \n                    }\n                }\n            }\n        }\n\n        /*\n        Now, we just have to return the sum of all the possible binary trees \n        for each integer as root, modulo by 10^9+7.\n        */\n\n        long long int ans = 0;\n        for(auto it: mp){\n            ans+=it.second;\n        }\n        return ans%(1000000007);\n    }\n};\n```
['C++']