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.
In [1]:
import math
for n in range(11,1000000):
if n == sum([math.factorial(int(d)) for d in str(n)]):
print n
In [2]:
145 + 40585
Out[2]: