login
A034705
Numbers that are sums of consecutive squares.
31
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,3
COMMENTS
Also, differences of any pair of square pyramidal numbers (A000330). These could be called "truncated square pyramidal numbers". - Franklin T. Adams-Watters, Nov 29 2006
If n is the sum of d consecutive squares up to m^2, n = A000330(m) - A000330(m-d) = d*(m^2 - (d-1)m + (d-1)(2d-1)/6 <=> m^2 - (d-1)m = c := n/d - (d-1)(2d-1)/6 <=> m = (d-1)/2 + sqrt((d-1)^2/4 + c) which must be an integer. Moreover, A000330(x) >= x^3/3, so m and d can't be larger than (3n)^(1/3). - M. F. Hasler, Jan 02 2024
EXAMPLE
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.
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 *)
PROG
(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
(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
CROSSREFS
Cf. A217843-A217850 (sums of consecutive powers 3 to 10).
Cf. A368570 (first of each pair of consecutive integers in this sequence).
Sequence in context: A060199 A229240 A322135 * A006844 A022425 A277549
KEYWORD
nonn
EXTENSIONS
Terms a(1..10^4) double-checked with independent code by M. F. Hasler, Jan 02 2024
STATUS
approved