cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

A353295 Square nearest to the sum of the first n positive squares.

Original entry on oeis.org

0, 1, 4, 16, 25, 49, 100, 144, 196, 289, 400, 484, 625, 841, 1024, 1225, 1521, 1764, 2116, 2500, 2916, 3364, 3844, 4356, 4900, 5476, 6241, 6889, 7744, 8464, 9409, 10404, 11449, 12544, 13689, 14884, 16129, 17689, 19044, 20449, 22201, 23716, 25600, 27556, 29241
Offset: 0

Views

Author

Paolo Xausa, Jun 04 2022

Keywords

Examples

			a(4) = 25 because the sum of the first 4 positive squares is 1 + 4 + 9 + 16 = 30, and the nearest square is 25.
		

Crossrefs

Programs

  • Mathematica
    nterms=100;Array[Round[Sqrt[#(#+1)(2#+1)/6]]^2&,nterms,0]
  • 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

Formula

a(n) = A053187(A000330(n)).