All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars    
perplexus dot info

Home > Numbers
Squared average equals square (Posted on 2019-08-09) Difficulty: 3 of 5
Find n consecutive perfect squares (n > 1)whose average is n2.

No Solution Yet Submitted by Danish Ahmed Khan    
No Rating

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution computer solution Comment 3 of 3 |
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

Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (0)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (19)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2024 by Animus Pactum Consulting. All rights reserved. Privacy Information