Concise Java solution using HashMap with detailed explanation. Easily understand!!!
```\n/*sort the array\n * and use HashMap to record each Integer, and the number of trees with that Integer as root\n * (1) each integer A[i] will always have o
```\n/**sort the array\n * and use HashMap to record each Integer, and the number of trees with that Integer as root\n * (1) each integer A[i] will always have one tree with only itself\n * (2) if A[i] has divisor (a) in the map, and if A[i]/a also in the map\n *     then a can be the root of its left subtree, and A[i]/a can be the root of its right subtree;\n *     the number of such tree is map.get(a) * map.get(A[i]/a)\n * (3) sum over the map\n */\nclass Solution {    \n    public int numFactoredBinaryTrees(int[] A) {\n        Arrays.sort(A);\n        Map<Integer, Long> map = new HashMap();\n        long count = 1;\n        map.put(A[0], count);\n        for (int i = 1; i < A.length; i++) {\n            count = 1;\n            for (Integer n : map.keySet()) {\n                if (A[i] % n == 0 && map.containsKey(A[i] / n)) {\n                    count += map.get(n) * map.get(A[i] / n);\n                }\n            }\n            map.put(A[i], count);\n        }\n        long sum = 0;\n        for (Integer n : map.keySet()) {\n            sum = (sum + map.get(n)) % ((int) Math.pow(10, 9) + 7) ;\n        }\n        return (int) sum;\n    }        \n}
[]