After first getting a program to find the first solution, it was quite slow in searching larger numbers. Having then seen Charlie's solution and Sloane's A189173, I made the algorithm more efficient and ran the loop up to 100,000. I found the first 3 solutions (it took about 40 minutes):
n starting number
47 22
2161 989
99359 45450
(Python):
def sumSqrs(f,n):
""" Starting with f, consider f,f+1,f+2, ... , f+n-1
take their squares
output the sum """
ans=0
for i in range(f,f+n):
ans += i**2
return ans
lastNum = 100000
foundOne = False
guessRatio = .5
for n in range (2,lastNum):
goal = n**3
guessFirstNumber = int(n*guessRatio) + 1
sumNow = sumSqrs(guessFirstNumber, n)
looking = True
while looking:
if sumNow == goal:
print(n,guessFirstNumber)
foundOne = True
guessRatio = guessFirstNumber / n
break
elif sumNow > goal:
guessFirstNumber -= 1
sumNow = sumNow - 2*n*guessFirstNumber - n**2
elif sumNow < goal:
# went too far, didn' find one for this n
looking = False
Edited on July 17, 2020, 12:11 pm
|
Posted by Larry
on 2020-07-17 12:10:51 |