Program | PRIME.C, PRIME.CPP, PRIME.PAS |
Webster defines prime as:
The most relevant definition for this problem is 2a: An integer g >1 is said to be prime if and only if its only positive divisors are itself and one (otherwise it is said to be composite). For example, the number 21 is composite; the number 23 is prime. Note that the decompositon of a positive number g into its prime factors, i.e.,
One interesting class of prime numbers are the so-called Mersenne primes which are of the form 2p- 1. Euler proved that 231 - 1 is prime in 1772 — all without the aid of a computer.
The input will consist of a sequence of numbers. Each line of input will contain one number g in the range - 231< g < 231 . The end of input will be indicated by an input line having a value of zero.
For each line of input, your program should print a line of output consisting of the input number and its prime factors. For an input number 0 < g = f1 x f2 x... x fn, where each fi is a prime number greater than unity (with fi <= fj for i < j), the format of the output line should be
For an input number 0 > g = f1 x f2 x... x fn,, the format of the output line should be
The following is sample input for this problem.
-190
-191
198
The following is the corresponding output for the input above.
-190 = -1 x 2 x 5 x 19
-191 = -1 x 191
198 = 2 x 3 x 3 x 11