Number Card Game
InterviewTime limit1sMemory limit128 MB
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 . 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 gives . Since still has two digits, we get , and then . Because is a single digit, the game ends.
Likewise, starting from proceeds as follows and ends at .
Given a natural number , 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 (). does not start with . The last line of the input contains a single , 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.