OFFSET
1,3
COMMENTS
|a(n)| takes its locally maximal values when n is a triangular number, the maximal values being given by A019298.
The maximal positive/negative values occur for n = 1, 3, 6, 10, 15, 21 ... the triangular numbers and are a(n) = 1, -4, 11, -23, 42, -69,106, 215, 381, 616 ... +- int(sqrt(n^3/2) + 0.22098 * sqrt(n)). a(n) = n for n = 5, 13, 25, 41, 61, 85, ... m*(m*2-2)+1 and the previous number is equal to 0. Positive numbers which do not occur in this sequence are 2, 3, 6, 7, 8, 10, 12, 14, 15, 17, 18, 19, 20, 21, 22, 23, 24, 28, 29, 30, 31, 32, 33, 34, 35, 37, 38, 39, 40, 43, 44, 45, 46, 48, ...
LINKS
Harry J. Smith, Table of n, a(n) for n = 1..1000
FORMULA
a(n) = Sum_{k=1..n} (-1)^(A002024(k)+1)*k.
EXAMPLE
a(9) = -13 because 1 - 2 - 3 + 4 + 5 + 6 - 7 - 8 - 9 = -13.
MAPLE
a := proc(n) option remember: if n=1 then RETURN(1) fi: a(n-1) + n*(-1)^( floor(1/2 + sqrt(2*n)+1)); end: for n from 1 to 150 do printf(`%d, `, a(n)) od:
MATHEMATICA
Accumulate[Flatten[Table[(-1)^(n+1) Range[(n(n-1))/2+1, (n(n+1))/2], {n, 15}]]] (* Harvey P. Dale, Apr 22 2015 *)
PROG
(PARI) t(n) = floor(1/2+sqrt(2*n)) for(n=1, 200, print1(sum(k=1, n, (-1)^(t(k)+1)*k), " "))
(PARI) t(n)= { floor(sqrt(2*n) + 1/2) } { for (n=1, 1000, a=sum(k=1, n, (-1)^(t(k) + 1)*k); write("b064520.txt", n, " ", a) ) } \\ Harry J. Smith, Sep 17 2009
(Python)
from math import isqrt
def A064520(n): return sum(k if (isqrt(k<<3)+1>>1)&1 else -k for k in range(1, n+1)) # Chai Wah Wu, Oct 16 2022
CROSSREFS
KEYWORD
AUTHOR
Jonathan Ayres (jonathan.ayres(AT)btinternet.com), Oct 07 2001
EXTENSIONS
STATUS
approved