145 is a curious number, as 1! + 4! + 5! = 1 + 24 + 120 = 145.
Find the sum of all numbers which are equal to the sum of the factorial of their digits.
Note: As 1! = 1 and 2! = 2 are not sums they are not included.
Similar to last question, we need to find the limit to how far we should search for these numbers. Consider a 5 digit number. Then, the maximum digit factorials is 5 * 9! = 1814400. Let's look at 8 digits: 8 * 9! = 2903040, only has 7 digit. How about 7 digit? 7 * 9! = 2540160, which has 7 digit like we wanted! It's impossible for an 8 digit number to have its digit factorial to equal to its number. The maximum is 2903040 which only has 7 digits. So, we only have to check up to 2540160. Coding factorials and checking this is simple!
Answer: 40730
Runtime: 29.3 seconds