- 問題
Problem 34:Digit factorials
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.
- 解答例
import math sum = 0 for i in range(3, math.factorial(9) * 7 + 1): temp = 0 strNum = list(str(i)) for n in strNum: temp += math.factorial(int(n)) if i == temp: sum += temp print(sum)