码迷,mamicode.com
首页 > 编程语言 > 详细

欧拉计划(python) problem 30

时间:2015-02-01 16:11:28      阅读:209      评论:0      收藏:0      [点我收藏+]

标签:

Digit fifth powers

Problem 30

Surprisingly there are only three numbers that can be written as the sum of fourth powers of their digits:

1634 = 14 + 64 + 34 + 44
8208 = 84 + 24 + 04 + 84
9474 = 94 + 44 + 74 + 44

As 1 = 14 is not a sum it is not included.

The sum of these numbers is 1634 + 8208 + 9474 = 19316.

Find the sum of all the numbers that can be written as the sum of fifth powers of their digits.


Answer:
443839
Completed on Sun, 1 Feb 2015, 06:58

Go to the thread for problem 30 in the forum.

python code:

def func(i):
    result=0
    temp=str(i)
    for i in range(0,len(temp)):
        result+=pow(int(temp[i]),5)
    return result


result=0
for i in range(2,1000000):
    if func(i)==i:
        print(i)
        result+=i
print("last result:"+str(result))


time: 1s

欧拉计划(python) problem 30

标签:

原文地址:http://blog.csdn.net/zhangzhengyi03539/article/details/43371737

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!