Problem 34
Posted noonjuan
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Problem 34相关的知识,希望对你有一定的参考价值。
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)
以上是关于Problem 34的主要内容,如果未能解决你的问题,请参考以下文章