✅Accepted easy Java Code || Beats 97%
Complexity :\n> n is length of array.\n> m is number of factors of any element in that array / 2.\n- Time complexity : O(n*m)\n Add your time complexity here, e
# Complexity :\n> *n is length of array.*\n> *m is number of factors of any element in that array / 2.*\n- Time complexity : $$O(n*m)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity : $$O(n)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n## Variables used :\n> map -> map of arr[ i ] and i\n> res -> result DP array\n> F1 -> Factor of a any number \'num\' in array\n> F2 -> Another factor of num with F1. ie. ( F1 * F2  = num)\n> k -> Doubling Factor. If both the sub-trees are different we need to double result. \n# Code :\n```java []\nclass Solution {\n    public int nextFact(int[] arr, int numI, int prevI){\n        int limit = (int)Math.sqrt(arr[numI]);\n        for(int i = prevI + 1; i < numI; i++){\n            if(arr[i] > limit) break;\n            if(arr[numI] % arr[i] == 0) return i;\n        }\n        return -1;\n    }\n    public int numFactoredBinaryTrees(int[] arr) {\n        Arrays.sort(arr);\n        int n = arr.length;\n        HashMap<Integer, Integer> map = new HashMap<>();\n        for(int i = 0; i < n; i++)\n            map.put(arr[i], i);\n        long[] res = new long[n];\n        Arrays.fill(res, 1);\n        int F1 = -1, F2; // F1 and F2 are index of factors\n        int k, mod = 1000000007;\n        long sum = 1;\n        for(int i = 1; i < n; i++, F1 = -1){\n            while((F1 = nextFact(arr, i, F1)) != -1){\n                F2 = arr[i] / arr[F1];\n                if(!map.containsKey(F2)) continue;\n                F2 = map.get(F2);\n                k = F1 == F2? 1 : 2;\n                res[i] = (res[i] + res[F1] * res[F2] * k)%mod;\n            }\n            sum = (long)(sum + res[i]) % mod;\n        }\n        return (int)sum;\n    }\n}\n```\n>>> ## Please, Upvote\uD83D\uDC4D if you find helpful
['Array', 'Hash Table', 'Dynamic Programming', 'Sorting', 'Java']