UVa 516

From Algorithmist
Jump to navigation Jump to search

516 - Prime Land[edit]

Summary[edit]

For this problem you have to know what the Prime Base Representation of a number is.

Use the Prime Sieve of Eratosthenes to create an array of all prime numbers less or equal than 32767, and then use the array to factor numbers.

Explanation[edit]

For the Prime Base Representation of a number you have to print the prime factors of the number and the frequency they appear in it's factorization (in decreasing order of prime factors). Something like this:

Where p is a decreasing sequence of primes and e is the corresponding sequence of powers of p. Each e must be greater than 0, so primes which are not factors are omitted from the prime base representation.

First you have to read a Prime Base Representation of a number and calculate just as you would expect by multiplying

Then you have to output the Prime Base Representation of .

For example, for the input

5 1 2 1

Then

and

Therefore, the output is

3 2

.

Input[edit]

17 1
5 1 2 1
509 1 59 1
3 1
151 1 31 1 7 1
131 1 5 3 2 1
0

Output[edit]

2 4
3 2
13 1 11 1 7 1 5 1 3 1 2 1
2 1
127 1 43 1 3 1 2 1
32749 1