20ms C++ easy to understand solution
Code\n\nclass Solution {\npublic:\n    int numFactoredBinaryTrees(vector<int>& arr) {\n        long M=1e9+7, ans=0;\n        set<int> s(arr.begin(), arr.end());
# Code\n```\nclass Solution {\npublic:\n    int numFactoredBinaryTrees(vector<int>& arr) {\n        long M=1e9+7, ans=0;\n        set<int> s(arr.begin(), arr.end());\n        map<int, int> mp;\n        for(int x : s){\n            long curr=1;\n            for(int y : s){\n                if((long)y * y > (long)x){\n                    break;\n                }\n                if(x%y==0){\n                    if(!s.count(x/y)){\n                        continue;\n                    }\n                    if(y != x/y){\n                        curr = (curr + (long)2*mp[x/y]*mp[y])%M;\n                    }else{\n                        curr = (curr + (long)mp[x/y]*mp[y])%M;\n                    }\n                }\n            }\n            mp[x]=curr;\n            ans=(ans+curr)%M;\n        }\n        return ans;\n    }\n};\n```
['C++']