Primorial Number System
Time limit1sMemory limit128 MB
Represent each positive integer in the mixed-radix primorial system where the i-th place value is the product of the first i primes.
- Level
Easy3 of 10
- Topics
- Math, Number theory, Simulation, Implementation
- Solved
- No attempts yet
Problem
For any natural number , every positive integer has a unique representation in base :
where each digit satisfies .
Let be the -th prime, so . Then every positive integer also has a unique representation in a numeral system whose place values are built from the primes. This is called the primorial number system.
Here each digit satisfies . For example, satisfies .
Given a positive integer , write a program that represents it in the primorial number system.
Input
The input consists of several test cases. Each test case is a single line containing one positive integer , with . The last line contains and is not processed.
Output
For each test case, output the given number, a space, an equals sign (), and a space, followed by the number written in the primorial number system.
Omit every term whose coefficient is , and join the remaining terms from the lowest place value upward with +. The constant term is printed as just its coefficient; for , the -th term is printed as the coefficient followed by the primes joined with an asterisk (*). For instance, the term is printed as 4*2*3*5.