EularProject 34: 一个数字与他每位数的阶乘和

标签: 欧拉计划
6922人阅读 评论(0) 收藏 举报
分类:

Digit factorials
Problem 34
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.

Answer:
40730
Completed on Wed, 8 Jul 2015, 17:34
Go to the thread for problem 34 in the forum.

from math import factorial

m=factorial(9)

def func(x):
    result=0
    while x>0:
        result+=factorial(x%10)
        x//=10
    return result
k=1
while True:
    if k*m<pow(10,k):
        break
    k+=1

result=0
for i in range(3,pow(10,k)):
    if i==func(i):
        result+=i
print(result)
1
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:323496次
    • 积分:5878
    • 等级:
    • 排名:第4516名
    • 原创:280篇
    • 转载:14篇
    • 译文:0篇
    • 评论:57条
    博客专栏
    最新评论