Factorial Sum List

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

All Submissions
Best Solutions


Point Value: 5
Time Limit: 2.00s
Memory Limit: 16M
Added: Feb 24, 2009

Languages Allowed:
C++03, PAS, C, HASK, ASM, RUBY, PYTH2, JAVA, PHP, SCM, CAML, PERL, C#, C++11, PYTH3

Comments (Search)

Before I browse every single problem, is there any other challenge like this (ie: in the project Euler spirit)?