Prime Land
InterviewTime limit1sMemory limit128 MB
Given an integer x in prime-base form (prime powers in decreasing order), print the same representation for x - 1.
- Level
Medium5 of 10
- Topics
- Number theory, Math, Implementation, Brute force
- Solved
- No attempts yet
Problem
In Prime Land everyone uses a prime-base number system. In this system every positive integer is written as follows. Let be the increasing sequence of all prime numbers, so , , , and so on. Every integer has exactly one factorization into prime powers, so there is an index and uniquely determined exponents with such that
The sequence is the representation of in the prime-base number system.
In this system multiplication and division are easy, but addition and subtraction are hard. Your task is the operation "minus one": given in prime-base representation, output in prime-base representation.
For convenience the prime-base representation is written as a sequence of pairs , listing only those for which , in decreasing order of .
Input
The input consists of one or more lines. Every line except the last holds the prime-base representation of a single integer with : the pairs (only those with ) in decreasing order of , with all numbers separated by single spaces. The last line contains a single and is not processed.
Output
For every input line except the last, print one line with in prime-base representation: the pairs (only those with ) in decreasing order of , separated by single spaces.