TopCoder problem "PersistentNumber" used in SRM 343 (Division II Level One)



Problem Statement

    Given a number x, we can define p(x) as the product of the digits of x. We can then form a sequence x, p(x), p(p(x))... The persistence of x is then defined as the index (0-based) of the first single digit number in the sequence. For example, using 99, we get the sequence 99, 9*9 = 81, 8*1 = 8. Thus, the persistence of 99 is 2. You will be given n, and you must return its persistence.
 

Definition

    
Class:PersistentNumber
Method:getPersistence
Parameters:int
Returns:int
Method signature:int getPersistence(int n)
(be sure your method is public)
    
 

Constraints

-n will be between 0 and 2,000,000,000, inclusive.
 

Examples

0)
    
99
Returns: 2
The example from the problem statement.
1)
    
268
Returns: 4
The sequence here is 268, 96, 54, 20, 0.
2)
    
6
Returns: 0
6 is already a single-digit number.
3)
    
68889789
Returns: 3
4)
    
86898
Returns: 7

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=7533

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=10667&pm=7533

Writer:

connect4

Testers:

PabloGilberto , brett1479 , Olexiy , lovro

Problem categories:

Simple Search, Iteration