(Challenge added over 7 years ago.)
Work out the prime factors of a given number.
As you know, a prime number is any number with no divisors other than itself and 1. It is possible to express any number as a product of a unique series of prime numbers. Your code should, for a given number, output the primes whose product equal that number. For example, for the number 34, the prime factors are 2 and 17.
Note that the same factor may need to be used more than once. For the number 232, the factors are 2, 2, 2 and 29.
Your code needs to output to a specific format. For the above two examples, your code should output
34: 2 17and
232: 2^3 29
That is, the number you are factoring followed by a colon (
:) and a space, followed by the prime factors in ascending order separated by spaces.
In the cases where there are factors repeated, they should be represented as
x is the factor and
y is the number of times the factor is repeated.
- Your code should be able to accept all numbers between 0 and 4,294,967,296 (2**32) inclusive.
- The number will be given to your code on stdin, and your output, matching the format described above, on stdout.
Your code will be run seven times with various numbers. For the first four runs, the same numbers will be used. You can see these numbers and the expected output by following the links :
We will use random numbers as the seeds for the remaining three runs. Click the following links to see examples of these numbers. Reload the resultant page to get a new number.