%I #24 Oct 17 2022 01:43:37
%S 1,-1,-4,0,5,11,4,-4,-13,-23,-12,0,13,27,42,26,9,-9,-28,-48,-69,-47,
%T -24,0,25,51,78,106,77,47,16,-16,-49,-83,-118,-154,-117,-79,-40,0,41,
%U 83,126,170,215,169,122,74,25,-25,-76,-128,-181,-235,-290,-234,-177,-119,-60,0,61,123,186,250,315,381,314,246,177
%N a(n) = + 1 - 2 - 3 + 4 + 5 + 6 - 7 - 8 - 9 - 10 + 11 + 12 + 13 + 14 + 15 - ... + (+-1)*n, where there is one plus, two minuses, three pluses, etc. (see A002024).
%C |a(n)| takes its locally maximal values when n is a triangular number, the maximal values being given by A019298.
%C 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, ...
%H Harry J. Smith, <a href="/A064520/b064520.txt">Table of n, a(n) for n = 1..1000</a>
%F a(n) = Sum_{k=1..n} (-1)^(A002024(k)+1)*k.
%e a(9) = -13 because 1 - 2 - 3 + 4 + 5 + 6 - 7 - 8 - 9 = -13.
%p 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:
%t Accumulate[Flatten[Table[(-1)^(n+1) Range[(n(n-1))/2+1,(n(n+1))/2], {n,15}]]] (* _Harvey P. Dale_, Apr 22 2015 *)
%o (PARI) t(n) = floor(1/2+sqrt(2*n)) for(n=1,200,print1(sum(k=1,n,(-1)^(t(k)+1)*k)," "))
%o (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
%o (Python)
%o from math import isqrt
%o 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
%Y Cf. A002024, A019298, A064528.
%K sign,look,easy
%O 1,3
%A Jonathan Ayres (jonathan.ayres(AT)btinternet.com), Oct 07 2001
%E More terms from _James A. Sellers_, _Jason Earls_ and _Vladeta Jovovic_, Oct 08 2001