CS 246 Lab 13

Write a program called factor that takes a single command line argument and prints the prime factorization of the number.

Use the following steps:

  1. Create a sieve of Erastosthenes to determine the primes up to the square root of the number.
  2. Count the primes, create an array of that size, and put the primes into the array.
  3. Divide each prime into the number. If a prime goes evenly, divide by the prime and continue dividing by that prime until it doesn't go evenly any more, counting the number of times that the prime divided the number evenly. Then print the prime and the power.
  4. Whatever is left of the number (if anything) is the last prime factor, so print it.

The output should look like this:

ubuntu16 10:21:20 > ./factor 1000
2^3 5^3
ubuntu16 10:21:23 > ./factor 347
347
ubuntu16 10:22:42 > ./factor 414470403
3^2 31 1485557