Primorial Number System

Time limit1sMemory limit128 MB

Summary
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 b≥2b \ge 2, every positive integer nn has a unique representation in base bb:

n=a0+a1b+a2b2+a3b3+⋯n = a_0 + a_1 b + a_2 b^2 + a_3 b^3 + \cdots

where each digit aia_i satisfies 0≤ai≤b−10 \le a_i \le b-1.

Let pip_i be the ii-th prime, so p0=2, p1=3, p2=5, …p_0 = 2,\ p_1 = 3,\ p_2 = 5,\ \dots. Then every positive integer nn also has a unique representation in a numeral system whose place values are built from the primes. This is called the primorial number system.

n=a0+a1p0+a2p0p1+a3p0p1p2+⋯n = a_0 + a_1 p_0 + a_2 p_0 p_1 + a_3 p_0 p_1 p_2 + \cdots

Here each digit aia_i satisfies 0≤ai≤pi−10 \le a_i \le p_i - 1. For example, a3a_3 satisfies 0≤a3≤p3−10 \le a_3 \le p_3 - 1.

Given a positive integer nn, 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 nn, with n≤231−1n \le 2^{31}-1. The last line contains 00 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 00, and join the remaining terms from the lowest place value upward with +. The constant term is printed as just its coefficient; for i≥1i \ge 1, the ii-th term is printed as the coefficient followed by the primes p0,p1,…,pi−1p_0, p_1, \dots, p_{i-1} joined with an asterisk (*). For instance, the term 4p0p1p24 p_0 p_1 p_2 is printed as 4*2*3*5.

Examples5

  1. Example 1

    Input
    123
    456
    123456
    0
    
    Expected output
    123 = 1 + 1*2 + 4*2*3*5
    456 = 1*2*3 + 1*2*3*5 + 2*2*3*5*7
    123456 = 1*2*3 + 6*2*3*5 + 4*2*3*5*7 + 1*2*3*5*7*11 + 4*2*3*5*7*11*13
    
  2. Example 2

    Input
    1
    0
    
    Expected output
    1 = 1
    
  3. Example 3

    Input
    2
    3
    4
    5
    0
    
    Expected output
    2 = 1*2
    3 = 1 + 1*2
    4 = 2*2
    5 = 1 + 2*2
    
  4. Example 4

    Input
    6
    30
    210
    2310
    0
    
    Expected output
    6 = 1*2*3
    30 = 1*2*3*5
    210 = 1*2*3*5*7
    2310 = 1*2*3*5*7*11
    
  5. Example 5

    Input
    7
    11
    13
    0
    
    Expected output
    7 = 1 + 1*2*3
    11 = 1 + 2*2 + 1*2*3
    13 = 1 + 2*2*3