privatevoidgetFactors(int n, int start, List<Integer> current, List<List<Integer>> results) { if (n == 1) { // Factor should be in range of [2, n] therefore if there is only one facotr in // the current list, we shouldn't consider this case if (current.size() > 1) { results.add(newArrayList<Integer>(current)); } return; }
for (inti= start; i <= (int) Math.sqrt(n); i++) { // ==> here, change 1 if (n % i != 0) { continue; } current.add(i); getFactors(n / i, i, current, results); current.remove(current.size() - 1); }
inti= n; // ===> here, change 2 current.add(i); getFactors(n / i, i, current, results); current.remove(current.size() - 1); } }