Find the sum of all the numbers that can be written as the sum of fifth powers of their digits.
In [56]:
5*9**5
Out[56]:
In [62]:
def calc(p):
n = {str(i):i**p for i in range(0, 10)}
a = []
for i in range(2, len(str(p*9**p))*(9**p)):
s = sum(n[i] for i in str(i))
if s == i and i > 9:
print(i)
a.append(i)
return sum(a)
In [63]:
calc(4)
Out[63]:
In [64]:
calc(5)
Out[64]: