Problem 11: Factorising

Description

This problem is the same as problem 12, except that the inputs are more restricted, so you will not need to be over-concerned witht the speed of your program.

Every positive integer can be decomposed into a list of prime factors. The idea is that if you multiply together all the numbers in the list, the result is the original number, and the numbers in the list must all be primes. For example, 280 is factorised as (2, 2, 2, 5, 7), 13 is factorised as (13), and 100 is factorised as (2, 2, 5, 5).

Your job is to write a program that reads in numbers and prints out their unique factorisations in a nice clear readable way.

The input to your program will be a long list of numbers, each on a separate line, with -1 at the end. The -1 is not an input to be factorised, it just signals the end of the input list. The numbers will all be between 2 and 10000 inclusive.

For each input number, your program should produce a single line of output, exactly following the samples given below. Note that the output uses the letter x to represent multiplication; the numbers and symbols are separated from each other with single spaces, but there are no spaces at the beginning or end of each line; the factors are listed in ascending order.

Input Format

The input will be a list of integers, one per line, with no spaces or other extra characters to worry about. The input list is terminated with -1.

Output Format

For each number is the input (call it N), a single line of output should be produced. If the number N is prime, the output should be exactly of the form "N = 1 x N". If the factors of N are A, B, C, D, E, such that A*B*C*D*E==N, all of A, B, C, D, and E are prime, and A<=B, B<=C, C<=D, and D<=E then the output should be exactly of the form "N = 1 x A x B x C x D x E". Note that the factor 1 always appears exactly once.

Sample Input

280
13
100
2
49
1024
1025
-1

Sample Output

280 = 1 x 2 x 2 x 2 x 5 x 7
13 = 1 x 13
100 = 1 x 2 x 2 x 5 x 5
2 = 1 x 2
49 = 1 x 7 x 7
1024 = 1 x 2 x 2 x 2 x 2 x 2 x 2 x 2 x 2 x 2 x 2
1025 = 1 x 5 x 5 x 41

Limits

2<=N and N<=10000 (ten thousand)

Clues

Generate all the prime numbers in ascending order. For each, count how many times you can divide it into N without there being any remainder.

Don't waste effort seeing if 1 is a factor; it is always printed.

End of Problem