OFFSET
0,3
LINKS
Paolo Xausa, Table of n, a(n) for n = 0..9999
EXAMPLE
a(4) = 25 because the sum of the first 4 positive squares is 1 + 4 + 9 + 16 = 30, and the nearest square is 25.
MATHEMATICA
nterms=100; Array[Round[Sqrt[#(#+1)(2#+1)/6]]^2&, nterms, 0]
PROG
(Python)
from math import isqrt
def a(n):
s = n*(n+1)*(2*n+1)//6
r = isqrt(s)
d1, d2 = s-r**2, (r+1)**2-s
return r**2 if d1 <= d2 else (r+1)**2
print([a(n) for n in range(45)]) # Michael S. Branicky, Jun 05 2022
CROSSREFS
KEYWORD
nonn,easy
AUTHOR
Paolo Xausa, Jun 04 2022
STATUS
approved