Here is a solution with 8 fifth powers:
[5206, 2436, 432, 152, 69, 16, 7, 6, 5]
I'm not sure if this algorithm might miss a better solution
goal = 7**22
def strip(guess,n):
""" start with first number, successive subtraction of guess^5 and
count the number of 5th powers to sum to goal """
count = 0
runningsum = guess**5
values = [guess]
diff = goal - runningsum
while diff > 0:
x = int(diff ** .2)
x5 = x**5
values.append(x)
runningsum += x5
diff = goal - runningsum
count += 1
return [count, values]
bestcount = 1000
bestvals = []
for n in range(5229,2,-1):
info = strip(n,goal)
thiscount = info[0]
thesevals = info[1]
if thiscount < bestcount:
bestcount = thiscount
bestvals = thesevals
print(bestcount)
print(bestvals)
|
Posted by Larry
on 2023-04-13 12:34:36 |