石头的专栏

A practice stone

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

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)
阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zhangzhengyi03539/article/details/46811065
文章标签: 欧拉计划
个人分类: Eular
所属专栏: EularProject
上一篇算法导论—中位数与顺序统计量
下一篇ML—广义线性模型导论
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭