← Back to challenges

Prime Factorization

PythonHardalgorithmsmathnumbers

Instructions

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.
python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.