JavaScript Simple DP Approach
Time: O(N^2)\nSpace: O(N)\njavascript\nvar numFactoredBinaryTrees = function(arr) {\n    const memo = new Map();\n    const mod = 10**9 + 7\n    \n    arr.sort(
Time: `O(N^2)`\nSpace: `O(N)`\n```javascript\nvar numFactoredBinaryTrees = function(arr) {\n    const memo = new Map();\n    const mod = 10**9 + 7\n    \n    arr.sort((a, b) => a - b);\n    arr.forEach(num => memo.set(num, 1))\n           \n    for(let i = 1; i < arr.length; i++) {\n        \n        for(let j = i-1; j >= 0; j--) {\n            \n            if(arr[i] % arr[j]) continue; // if the number doesn\'t divide \n            \n            const num2 = arr[i] / arr[j];;\n            \n            if(!memo.has(num2)) continue; // if the complimentary number doesn\'t exit\n            \n            const waysToNum1 = memo.get(arr[j]);\n            const waysToNum2 = memo.get(num2);\n            const totalWays = waysToNum1 * waysToNum2;\n            \n            memo.set(arr[i], (memo.get(arr[i]) + totalWays));\n        }\n    }\n    \n    const totalTrees = [...memo.values()].reduce((acc, cur) => acc + cur, 0);\n    return totalTrees % mod;\n};\n```
['Dynamic Programming', 'JavaScript']