Answers for "return prime factors of a number"

C#
0

Prime factors of a number

public List<Integer> factorsOf(int n) {
  ArrayList<Integer> factors = new ArrayList<>();

  for (int d = 2; n > 1; d++)
    for (; n % d == 0; n /= d)
      factors.add(d);

  return factors;
}
Posted by: Guest on May-13-2021

Code answers related to "return prime factors of a number"

C# Answers by Framework

Browse Popular Code Answers by Language