primeDecomp function

List<int> primeDecomp(
  1. int n
)

Returns the prime decomposition of n.

For example, 120 returns [2, 2, 2, 3, 5].

Implementation

List<int> primeDecomp(int n) {
  final a = <int>[];
  for (int i = 0, p = 2;;) {
    if (p * p > n) break;
    if (n % p != 0) {
      i += 1;
      p = primes.getPrime(i);
    } else {
      a.add(p);
      n ~/= p;
    }
  }
  if (n != 1) a.add(n);
  return a;
}