package com.fishercoder.solutions;

import java.util.ArrayList;
import java.util.List;

/**
 * Numbers can be regarded as product of its factors. For example,

 8 = 2 x 2 x 2;
 = 2 x 4.
 Write a function that takes an integer n and return all possible combinations of its factors.

 Note:
 You may assume that n is always positive.
 Factors should be greater than 1 and less than n.
 Examples:
 input: 1
 output:
 []
 input: 37
 output:
 []
 input: 12
 output:
 [
 [2, 6],
 [2, 2, 3],
 [3, 4]
 ]
 input: 32
 output:
 [
 [2, 16],
 [2, 2, 8],
 [2, 2, 2, 4],
 [2, 2, 2, 2, 2],
 [2, 4, 4],
 [4, 8]
 ]
 */
public class _254 {

    public List<List<Integer>> getFactors(int n) {
        List<List<Integer>> result = new ArrayList<List<Integer>>();
        helper(result, new ArrayList<Integer>(), n, 2);
        return result;
    }

    public void helper(List<List<Integer>> result, List<Integer> item, int n, int start) {
        if (n <= 1) {
            if (item.size() > 1) {
                result.add(new ArrayList<Integer>(item));
            }
            return;
        }

        for (int i = start; i <= n; ++i) {
            if (n % i == 0) {
                item.add(i);
                helper(result, item, n / i, i);
                item.remove(item.size() - 1);
            }
        }
    }

}

@@ -85,542 +85,69 @@
 t;%0A%0A
-/**%0A * Numbers can be regarded as product of its factors. For example,%0A%0A 8 = 2 x 2 x 2;%0A = 2 x 4.%0A Write a function that takes an integer n and return all possible combinations of its factors.%0A%0A Note:%0A You may assume that n is always positive.%0A Factors should be greater than 1 and less than n.%0A Examples:%0A input: 1%0A output:%0A %5B%5D%0A input: 37%0A output:%0A %5B%5D%0A input: 12%0A output:%0A %5B%0A %5B2, 6%5D,%0A %5B2, 2, 3%5D,%0A %5B3, 4%5D%0A %5D%0A input: 32%0A output:%0A %5B%0A %5B2, 16%5D,%0A %5B2, 2, 8%5D,%0A %5B2, 2, 2, 4%5D,%0A %5B2, 2, 2, 2, 2%5D,%0A %5B2, 4, 4%5D,%0A %5B4, 8%5D%0A %5D%0A */%0Apublic class _254 %7B%0A%0A
+public class _254 %7B%0A%0A    public static class Solution1 %7B%0A    
     
@@ -189,24 +189,28 @@
 rs(int n) %7B%0A
+    
         List
@@ -252,26 +252,17 @@
 ist%3C
-List%3CInteger%3E
 %3E();%0A
+    
     
@@ -294,23 +294,16 @@
 rayList%3C
-Integer
 %3E(), n, 
@@ -306,16 +306,20 @@
  n, 2);%0A
+    
         
@@ -333,27 +333,35 @@
 result;%0A    
+ 
-%7D%0A%0A
+   %7D%0A%0A    
     public v
@@ -443,24 +443,28 @@
 ) %7B%0A        
+    
 if (n %3C= 1) 
@@ -461,24 +461,28 @@
  (n %3C= 1) %7B%0A
+    
             
@@ -500,24 +500,28 @@
 ze() %3E 1) %7B%0A
+    
             
@@ -549,23 +549,16 @@
 rayList%3C
-Integer
 %3E(item))
@@ -563,34 +563,42 @@
 ));%0A            
+   
+ 
 %7D%0A
+    
             retu
@@ -601,16 +601,20 @@
 return;%0A
+    
         
@@ -624,16 +624,20 @@
         
+    
 for (int
@@ -671,24 +671,28 @@
             
+    
 if (n %25 i ==
@@ -709,24 +709,28 @@
             
+  
+  
 item.add(i);
@@ -726,24 +726,28 @@
 tem.add(i);%0A
+    
             
@@ -794,24 +794,28 @@
             
+   
+ 
 item.remove(
@@ -832,16 +832,34 @@
 ) - 1);%0A
+                %7D%0A
         
@@ -880,11 +880,10 @@
 %7D%0A    %7D%0A
-%0A
 %7D%0A

refactor 254