Prime Factorization

Published by Matt in

Create a function that returns the prime factorization of an integer as a sorted list of tuples. Include the multiplicity of each prime in the tuples:

  • [(prime_0, mult_0), ..., (prime_k, mult_k)]
  • where prime_0 < prime_1 < ... < prime_k

Examples

factorize(4) ➞ [[2, 2]]

factorize(10) ➞ [[2, 1], [5, 1]]

factorize(60) ➞ [[2, 2], [3, 1], [5, 1]]

Notes

  • Don't worry about negatives or floats. All inputs will be positive integers.
  • 1 is not a prime! Do not include it. You will not be given 1 as an input.
  • All inputs will be less than 10,000.
Watch a quick demo on how Edabit works.