1
2function primeFactors(n){
3 var factors = [],
4 divisor = 2;
5
6 while(n>2){
7 if(n % divisor == 0){
8 factors.push(divisor);
9 n= n/ divisor;
10 }
11 else{
12 divisor++;
13 }
14 }
15 return factors;
16}
17
18> primeFactors(69);
19 = [3, 23]
20
1public List<Integer> factorsOf(int n) {
2 ArrayList<Integer> factors = new ArrayList<>();
3
4 for (int d = 2; n > 1; d++)
5 for (; n % d == 0; n /= d)
6 factors.add(d);
7
8 return factors;
9}
10