UVa 516
From Algorithmist
Contents |
[edit] 516 - Prime Land
[edit] Summary
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.
[edit] Explanation
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:
pnenpn - 1en - 1...p1e1
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 x and calculate x just as you would expect by multiplying
Then you have to output the Prime Base Representation of x - 1.
For example, for the input5 1 2 1
Then x - 1 = 9
and
9 = 32
Therefore, the output is3 2.
[edit] Input
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
[edit] Output
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

