C++ || DP || Maps
\t\t// Provided logic comprises of working with factors of given number ans storing them in a hashmap which helps to achieve dynamic programming \n\t\t// Initia
\t\t// Provided logic comprises of working with factors of given number ans storing them in a hashmap which helps to achieve dynamic programming \n\t\t// Initially we create a map and keep on updating frequency as 1 for all elements in the given array, indicating that every element forms an independent tree\n\t\t// Further we traverse through the whole array to check the factors of the element\n\t\t// If we find one factor we have to check whether there is another factor available in the given array, whose product with current factor is the current element\n\t\t// If we find such a pair then we multiply number of trees of both the elements and finally multiply it with 2 becasue one node can have 2 possibilities of trees, and add it to the number of trees of current element\n\t\t// Further we check whether the square root of element is there or not, if it exists then we multiply the square root with itself and add it to number of trees\n\t\t// Finally we calculate total number of trees for all elements and the above dicussed logic satisfies all the test cases\n\t\tint mod = 1000000007;\n\t\tint numFactoredBinaryTrees(vector<int>& arr) {\n\t\t\tmap<int, long long> mp;\n\t\t\tsort(arr.begin(), arr.end());\n\t\t\tfor(auto i:arr){\n\t\t\t\tmp[i]=1;\n\t\t\t}\n\t\t\tfor(int i=0;i<arr.size();i++){\n\t\t\t\tfor(int j=2;j<sqrt(arr[i]);j++){\n\t\t\t\t\tif(arr[i]%j == 0 and (j * (arr[i]/j) == arr[i])){\n\t\t\t\t\t\tif(mp.find(j)!=mp.end() and mp.find(arr[i]/j)!=mp.end()){\n\t\t\t\t\t\t\tmp[arr[i]]+= (((((mp[j]%mod)*(mp[arr[i]/j]%mod))%mod)*2)%mod);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif(int(sqrt(arr[i]))*int(sqrt(arr[i])) == arr[i] and mp.find(sqrt(arr[i]))!=mp.end()){\n\t\t\t\t\tmp[arr[i]]+= (((mp[sqrt(arr[i])]%mod)*(mp[sqrt(arr[i])])%mod)%mod);\n\t\t\t\t}\n\n\t\t\t}\n\n\t\t\t//here int gives wrong answer since the number of trees can exceed the integer \n\t\t\tlong s = 0;\n\t\t\tfor(auto i:mp){\n\t\t\t\ts+= (i.second);\n\t\t\t}\n\n\t\t\t//mod of the final answer else it does not return an integer\n\t\t\treturn s%mod;\n\t\t}
['Dynamic Programming', 'C']