Skip to main content

Euler 0030

The Problem:

HowSurprisingly many distinct termsthere are inonly three numbers that can be written as the sequencesum generatedof byfourth a^bpowers of their digits: 1634, 8208, 9474  
We ignore 1 for athe andtrivial bcase,lol.

being

Find boundedthe tosum 2of andall 100the inclusive?numbers that can be written as the sum of fifth powers of their digits.

Considerations and Approach:

Naively,We thisneed to find an upper limit first, which we can do by adding 9^5 to a sum until the sum is onlyless processingthan 100*100the numbers,number notof reallydigits.
There muchis atno all.number
Wethat canis creategoing ato pythonfit setthese conditions above that upper limit.

Then we increment 1 to the upper limit and thenfind insertall everythese calculation, so it will remove the redundancy.  multiples

The Code:

lower_limit = 2
upper_limit = 1009**5
#create a set
distinctdigit_count = set()1

#go through#find the inclusiveupper rangeslimit
while len(str(upper_limit))/digit_count > 1:
    upper_limit += 9**5
    digit_count += 1

print(upper_limit, digit_count)

#calculate every number between here and there
digit_fifths = []
for i in range(lower_limit,2, upper_limitupper_limit):
    +current_digit_sum 1):= 0
    for j in range(lower_limit, upper_limit + 1):
        #do the set addition operator[int(x) for a^bx distinct.add(i*in str(i)]:
        current_digit_sum += j**j)5
    #printif howcurrent_digit_sum many== distincti:
        pairsdigit_fifths that+= we created[i]

print(len(distinct)digit_fifths)
print(sum(digit_fifths))