欧拉计划(python) problem


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.


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

评论关闭