# 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.
def factorial(x):
y=int(x)
n=1
fact=1
while n < y:
fact=fact*(n+1)
n=n+1
return fact
sum1 = 0
for j in range(10,100000):
str1 = str(j)
length = len(str1)
sum = 0
for i in range(1,length+1):
sum = sum + factorial(str1[i-1])
if sum == j:
sum1 = sum1 + sum
print sum1

### Like this:

Like Loading...