← Back to challenges

Complete Prime Factorization

PythonHardarraysmath

Instructions

Create a function that decomposes an integer into its prime factors, ordered from smallest to largest.

For instance:

complete_factorization(24) = [2, 2, 2, 3]
# Since 24 = 8 x 3 = 2^3 x 3 = 2 x 2 x 2 x 3

Examples

complete_factorization(10) ➞ [2, 5]

complete_factorization(9) ➞ [3, 3]

complete_factorization(72) ➞ [2, 2, 2, 3, 3]

Notes

1 is not considered a prime number, so omit it in your final list of prime factors.

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.