A034705 Numbers that are sums of consecutive squares.
0, 1, 4, 5, 9, 13, 14, 16, 25, 29, 30, 36, 41, 49, 50, 54, 55, 61, 64, 77, 81, 85, 86, 90, 91, 100, 110, 113, 121, 126, 135, 139, 140, 144, 145, 149, 169, 174, 181, 190, 194, 196, 199, 203, 204, 221, 225, 230, 245, 255, 256, 265, 271, 280, 284, 285, 289, 294, 302
Offset: 1
Keywords
Examples
All squares (A000290: 0, 1, 4, 9, ...) are in this sequence, since "consecutive" in the definition means a subsequence without interruption, so a single term qualifies. 5 = 1^2 + 2^2 = A000330(2) is in this sequence, and similarly 13 = 2^2 + p3^2 = A000330(3) - A000330(1) and 14 = 1^2 + 2^2 + 3^2 = A000330(3), etc.
Links
Crossrefs
Programs
-
Haskell
import Data.Set (deleteFindMin, union, fromList); import Data.List (inits) a034705 n = a034705_list !! (n-1) a034705_list = f 0 (tail $ inits $ a000290_list) (fromList [0]) where f x vss'@(vs:vss) s | y < x = y : f x vss' s' | otherwise = f w vss (union s $ fromList $ scanl1 (+) ws) where ws@(w:_) = reverse vs (y, s') = deleteFindMin s -- Reinhard Zumkeller, May 12 2015
-
Mathematica
nMax = 1000; t = {0}; Do[k = n; s = 0; While[s = s + k^2; s <= nMax, AppendTo[t, s]; k++], {n, Sqrt[nMax]}]; t = Union[t] (* T. D. Noe, Oct 23 2012 *)
-
PARI
{is_A034705(n)= for(d=1,sqrtnint(n*3,3), my(b = (d-1)/2, s = n/d - (d-1)*(d*2-1)/6 + b^2); denominator(s)==denominator(b)^2 && issquare(s, &s) && return(b+s)); !n} \\ Return the index of the largest square of the sum (or 1 for n = 0) if n is in the sequence, else 0. - M. F. Hasler, Jan 02 2024
-
Python
import heapq from itertools import islice def agen(): # generator of terms m = 0; h = [(m, 0, 0)]; nextcount = 1; v1 = None while True: (v, s, l) = heapq.heappop(h) if v != v1: yield v; v1 = v if v >= m: m += nextcount*nextcount heapq.heappush(h, (m, 1, nextcount)) nextcount += 1 v -= s*s; s += 1; l += 1; v += l*l heapq.heappush(h, (v, s, l)) print(list(islice(agen(), 60))) # Michael S. Branicky, Jan 06 2024
Extensions
Terms a(1..10^4) double-checked with independent code by M. F. Hasler, Jan 02 2024
Comments