Problem 34
https://projecteuler.net/problem=34
145 is a curious number, as 1! + 4! + 5! = 1 + 24 + 120 = 145.
145是一个神奇的数字,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.
注意:不包括1和2。
def factorial(num): f = 1 for i in range(1, num+1): f *= i return f tot = 0 nums = [] for i in range(3, 99999): print(i) digits = list(str(i)) if i < factorial(int(max(digits))): continue multi = 0 for digit in digits: multi += factorial(int(digit)) if multi == i: nums.append(i) tot += i print(nums) print(tot)
原文地址:https://www.cnblogs.com/noonjuan/p/11031246.html
时间: 2024-11-08 10:35:34