TopCoder problem "AdditionCycles" used in SRM 326 (Division II Level One)



Problem Statement

    

Start with any integer between 00 and 99, inclusive, written as two digits (use a leading zero if the number is less than 10). Add the two digits together. Now concatenate the rightmost digit of the first number with the rightmost digit of the sum to get a new number. If you repeat this process enough times, you'll end up back at the original number. For example:



			    Combine Second Digits of
Start With    Add Digits    the Original and the Sum
------------------------------------------------------
    26     :   2+6 = 08   :   "6" and "8" = 68 
    68     :   6+8 = 14   :   "8" and "4" = 84
    84     :   8+4 = 12   :   "4" and "2" = 42
    42     :   4+2 = 06   :   "2" and "6" = 26

In this case, it took us 4 steps to get back to where we started, so we would return 4. Starting with n, return the number of steps it takes to get back to n.

 

Definition

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

Constraints

-n will be between 0 and 99, inclusive.
 

Examples

0)
    
26
Returns: 4
The example from the problem statement. It goes 26->68->84->42->26, so there's 4 steps for the cycle.
1)
    
55
Returns: 3
The cycle is 55->50->05->55. Remember to treat numbers under 10 as though there was a leading zero.
2)
    
0
Returns: 1
Zero comes back to zero at every step - so the length of the cycle is one (00->00)
3)
    
71
Returns: 12

Problem url:

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

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=10006&pm=6736

Writer:

jmzero

Testers:

PabloGilberto , brett1479 , Olexiy , lovro

Problem categories:

Simple Math