package leetcode;

/**
 * https://leetcode.com/problems/binary-trees-with-factors/
 */
public class Problem823 {
    public int numFactoredBinaryTrees(int[] A) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem823 prob = new Problem823();
        System.out.println(prob.numFactoredBinaryTrees(new int[]{2, 4})); // 3
        System.out.println(prob.numFactoredBinaryTrees(new int[]{2, 4, 5, 10})); // 7
    }
}

@@ -167,32 +167,1028 @@
     
-// TODO%0A        return 0
+boolean%5B%5D set = new boolean%5B1001%5D;;%0A        for (int a : A) %7B%0A            set%5Ba%5D = true;;%0A        %7D%0A        int answer = 0;%0A        for (int i = 0; i %3C set.length; i++) %7B%0A            if (!set%5Bi%5D) %7B%0A                continue;%0A            %7D%0A            answer += numFactoredBinaryTrees(set, i);%0A        %7D%0A        return answer;%0A    %7D%0A%0A    private static int numFactoredBinaryTrees(boolean%5B%5D set, int root) %7B%0A        int count = 1;%0A        set%5Broot%5D = false;;%0A        for (int i = 0; i %3C set.length; i++) %7B%0A            if (!set%5Bi%5D) %7B%0A                continue;%0A            %7D%0A            if (root %25 i == 0) %7B%0A                int j = root / i;%0A                if (set%5Bj%5D) %7B%0A                    set%5Bi%5D = false;%0A                    count += numFactoredBinaryTrees(set, i);%0A                    set%5Bi%5D = true;%0A%0A                    set%5Bj%5D = false;%0A                    count += numFactoredBinaryTrees(set, j);%0A                    set%5Bj%5D = true;%0A                %7D%0A            %7D%0A        %7D%0A        set%5Broot%5D = true;%0A        return count
 ;%0A  

Update problem 823