Let's solve a commonly misunderstood problem in computer science - finding the prime factors of a number. Almost all modern cryptography, including your browser's HTTPS encryption, is based on the fact that prime factorization is slow.
For now, let's focus on the speed of factorization, and how it relates to P and NP.
Finding a number's prime factors is an NP algorithm.
The trouble is that no one has formally proven that there is not a polynomial time algorithm for finding prime factors. So, we're technically unsure if the problem is in P or if it's NP-complete.
Either way, let's build it!
Given a large number, return a list of all the prime factors.
prime_factors(8) -> [2, 2, 2]prime_factors(10) -> [2, 5]prime_factors(24) -> [2, 2, 2, 3]Complete the prime_factors function according to the given algorithm. Notice how the algorithm gets much slower as the size of the input (in bits) grows.
The returned list should only contain ints, no floats.