Java accepted solution
for num i, if m * n == i, number of trees for i is 1 + count(m) * count(n), means root i self, add number of trees when m is root times number of trees when n i
for num `i`, if `m * n == i`, number of trees for `i` is `1 + count(m) * count(n)`, means root `i` self, add number of trees when `m` is root times number of trees when `n` is root.\n```\n    public int numFactoredBinaryTrees(int[] A) {\n        if(A==null || A.length==0)\n            return 0;\n        Map<Integer,Long> map = new HashMap<>();\n        Arrays.sort(A);\n        for(int i=0; i<A.length; i++){\n            long count = 1;\n            for(int j=0; j<i; j++){\n                if(A[i]%A[j]==0 && map.containsKey(A[i]/A[j])){\n                    count += map.get(A[i]/A[j]) * map.get(A[j]);\n                }\n            }\n            map.put(A[i],count);\n        }\n        long sum = 0;\n        for(long cnt : map.values())\n            sum += cnt;\n        return (int) (sum % (Math.pow(10,9) + 7));\n    }\n```\n
[]