Prime factorization¶
The prime factors of 360 are
\[360 = 2 \cdot 2 \cdot 2 \cdot 3 \cdot 3 \cdot 5 = 2^3 \cdot 3^2 \cdot 5.\]
Write a function that returns a dictionary whose first keys correspond to the prime factor and the value to the multiplicity of this prime factor. For example, given 360 the function should return:
{
2: 3,
3: 2,
5: 1
}
-
prime_factorization
(n)¶ Return the prime factorization of n.
Parameters: n (int) – The number for which the prime factorization should be computed. Returns: List of tuples containing the prime factors and multiplicities of n. Return type: dict[int, int]
Start by downloading the
exercise template
and editing
this file. You can run tests via
$ python prime_factorization.py test
to check whether you got a correct solution. You can also take a look at
one possible solution
.