WOBURN CCC PRACTICE

FACTORIAL SUM LIST

INPUT FILE: fact.in
OUTPUT FILE: fact.out

Start with any number, say 25. Find the sum of the factorial (N! = N factorial = 1 x 2 x 3 x ... x N; 0! = 1 by convention) of each of the digits of 25: 2! + 5! = 2 + 120 = 122. Repeat this procedure (in this case you will get 1! + 2! + 2! = 1 + 2 +2 =5). Continue summing the factorials of individual digits until your list repeats a number. For example for 25 you will get the following list:
25 122 5 120 4 24 26 722 5044 169 363601 1454 169
At this point you got a repetition (169), so your list will repeat forever and you'd might as well stop now. Your list has 13 elements.

Write a program that asks the user to enter any number from 1 to 9999999 and computes the FACTORIAL SUM LIST until a duplicate number is found. The output for your program should be the length of your list.

INPUT
Integer numbers, one per line. The end of data is signaled by the number 0.

OUTPUT
The length of the FACTORIAL SUM LIST for each number in the input file

SAMPLE DATA

Input file

25
0

Output file

13
Downloader failed! Response object 006~ASP 0159~Buffering Off~Buffering must be on.