Persistence
InterviewTime limit1sMemory limit256 MB
Count how many times multiplying the decimal digits together reduces the given number to a single digit.
- Level
Easy1 of 10
- Topics
- Simulation, Implementation
- Solved
- No attempts yet
Problem
Kipa likes multiplication. When Kipa sees a number, Kipa multiplies all of its digits together to build a new number, then repeats the same work on that new number. Once the number has only one digit there is nothing left to multiply, and Kipa becomes sad.
Write a program that prints how many steps Kipa's joy lasts. For example, shrinks like this.
- (step 1)
- (step 2)
- (step 3)
- (step 4)
- (step 5, the number now has one digit and Kipa becomes sad)
reaches one digit after 5 steps, so the answer is 5.
Input
The first line contains one integer with at most 9 digits and no leading zero. ()
Output
Print the number of steps Kipa's joy lasts on the first line. If already has one digit, print 0.