Euler Solution 30

From ProgSoc Wiki

Jump to: navigation, search

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

Solutions for Problem 30

Python by Althalus

Runtime: 3.5 seconds

"Find all numbers that can be expressed as a sum of the 5th power of it's digits"
This problem doesn't tell us how far up to go. Just that we have to
"Find them all".
We know we can stop when the sum of the 5th powers isn't big enough anymore.
ie the highest 5 digit number is 99999. 9^5+9^5+9^5+9^5+9^5 = 295245.
This easily fits every 5 digit number.
For 6 digit numbers, (9^5)*6=354294
Since this is a 6 digit number, this is as high as we need to go. Nothing above
this point will fit the requirement.


fives = []

for i in range(2,354294):
    total = 0
    for c in str(i):
        total += int(c)**5
    if total == i: fives.append(i)

print(sum(fives))
Personal tools