Code with Finding: |
class Primes {
/**
* Prime factors decomposition
*
* @param n number to factorize: must be ≥ 2
* @return list of prime factors of n
* @throws MathIllegalArgumentException if n < 2.
*/
public static List<Integer> primeFactors(int n) {
if (n < 2) {
throw new MathIllegalArgumentException(LocalizedFormats.NUMBER_TOO_SMALL, n, 2);
}
// slower than trial div unless we do an awful lot of computation
// (then it finally gets JIT-compiled efficiently
// List<Integer> out = PollardRho.primeFactors(n);
return SmallPrimes.trialDivision(n);
}
}
|