首页 > 代码库 > 欧拉计划(python) problem 30

欧拉计划(python) problem 30

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