[C++]  Most Efficient approach , beats 99%
Simple Approach\n1. Assume dp[i] is the number of combinations and the recurrence relation is:\ndp[i]=1+sum(dp[j]dp[k]) for j=0 to i-1 and A[k]=A[i]/A[j]\nwe ha
***Simple Approach***\n1. Assume dp[i] is the number of combinations and the recurrence relation is:\n***dp[i]=1+sum(dp[j]*dp[k]) for j=0 to i-1 and A[k]=A[i]/A[j]***\n*we have to sort the array in ascending order so that the recurrence relation is correct.*\n\n2. Use the hash set to store all the numbers before i to save lookup time.\nBe sure to use **long long** for **dp[j]*dp[k]**, otherwise it will overflow.\nalso the accumulation has to use 0LL for the initial value to avoid overflow.\n```\nclass Solution {\npublic:\n    int numFactoredBinaryTrees(vector<int>& A) {\n        //a single node automatically satisify\n        //for any number we shall try all possible combinations\n        vector<long long> dp(A.size(),1);//long long is key!\n        sort(A.begin(),A.end());\n        const int tt=1000000000+7;\n        //A[i]=A[j]*A[i/j]\n        unordered_map<int,int> ms;//value with index\n        for(int i=0;i<A.size();i++)\n        {\n            ms[A[i]]=i;\n            for(int j=i-1;j>=0;j--) \n            {\n                if(A[i]%A[j]==0)//find one factor\n                {\n                    int t=A[i]/A[j];\n                    if(ms.count(t)) dp[i]+=(dp[j]*dp[ms[t]])%tt;\n                }\n            }\n        }\n        //copy(dp.begin(),dp.end(),ostream_iterator<int>(cout," "));\n        long long ans=0;\n        ans=accumulate(dp.begin(),dp.end(),0LL);\n        //for(int i=0;i<dp.size();i++) ans=(ans+dp[i])%tt;\n        return ans%tt;//%tt+7;\n    }\n};\n\nPLEASE UPVOTE ****
['Dynamic Programming', 'C']