This page is still under construction.

Parts of this page are still being built. What you see may change.

Number Card Game

Interview

Time limit1sMemory limit128 MB

Summary
For each starting number S, repeatedly replace it with the product of its digits until a single digit appears, printing every value in order.
Level

Easy2 of 10

Topics
Simulation, Implementation, Math, Array
Solved
No attempts yet

Problem

Sitting in the very front row, Sanggun cannot fool around no matter how boring the class is. But today he simply cannot resist, so he decides to play the "number card game" in his notebook.

The number card game works as follows. First, choose a natural number SS. Then multiply all of its digits together to form a new number. Repeat this process until the result becomes a single-digit number.

For example, starting from 9595 gives 9×5=459 \times 5 = 45. Since 4545 still has two digits, we get 4×5=204 \times 5 = 20, and then 2×0=02 \times 0 = 0. Because 00 is a single digit, the game ends.

Likewise, starting from 396396 proceeds as follows and ends at 22.

3×9×6=1623 \times 9 \times 6 = 162

1×6×2=121 \times 6 \times 2 = 12

1×2=21 \times 2 = 2

Given a natural number SS, write a program that prints the process of the number card game.

Input

The input consists of several test cases. Each test case is a single starting value SS (1≤S≤1000001 \le S \le 100000). SS does not start with 00. The last line of the input contains a single 00, which must not be processed.

Output

For each nonzero input, print on one line all the numbers that appear until the game ends, separated by single spaces. The first number is the given input value, and the last number is a single digit.

Examples1

  1. Example 1

    Input
    95
    396
    28
    4
    40
    0
    
    Expected output
    95 45 20 0
    396 162 12 2
    28 16 6
    4
    40 0