Surprisingly, there are only three numbers where the sum of each digit squared matches the original number.
1634 = 1**4 + 6**4 + 3**4 + 4**4
8208 = 8**4 + 2**4 + 0**4 + 8**4
9474 = 9**4 + 4**4 + 7**4 + 4**4
However, it does not include 1 = 1 ** 4
. The sum of these numbers is 1634 + 8208 + 9474 = 19316
.
Find the sum of the numbers so that the sum of the numbers raised to the fifth power of each digit matches the original number. http://odz.sakura.ne.jp/projecteuler/index.php?cmd=read&page=Problem%2030
Wrist exercise.
def main():
MAX = (9**5)*6+1
ls = [x**5 for x in range(10)]
ans = 0
for num in range(2,MAX):
wa = sum(map(lambda x: ls[int(x)], str(num)))
if wa == num:
ans += num
print ans
main()
Recommended Posts