login

Year-end appeal: Please make a donation to the OEIS Foundation to support ongoing development and maintenance of the OEIS. We are now in our 61st year, we have over 378,000 sequences, and we’ve reached 11,000 citations (which often say “discovered thanks to the OEIS”).

A309764
a(0)=0; for n > 0, a(n) = a(n-1) + d * n, where initially d = 1 but changes sign whenever n = |a(k)|, 0 < k < n.
1
0, 1, 3, 0, -4, -9, -15, -22, -30, -21, -11, -22, -34, -47, -61, -46, -30, -13, 5, 24, 44, 23, 45, 22, 46, 71, 97, 124, 152, 181, 151, 120, 88, 55, 89, 124, 160, 197, 235, 274, 314, 355, 397, 440, 396, 441, 395, 442, 490, 539, 589, 640, 692, 745, 799, 744, 688, 631, 573, 514
OFFSET
0,3
COMMENTS
The sequence oscillates erratically from above to below zero. For n <= 10^9 it changes sign 1823 times, with the longest gap between changes occurring from n = 312214179 to n = 703640490, a run of 391426311 negative values. The maximum run without d changing sign starts at n = 726820728 and goes for 43207 values. The longest run of consecutive sign changes in d is four, which occurs four times, at n = 21, 44, 395, and 439. In total d changes sign 675277 times. The largest positive a(n) is for n = 765504445 with a(n) = 496154732190565. The largest negative a(n) is for n = 951481398 with a(n) = -618690200847941.
LINKS
EXAMPLE
a(2) = 3, d = 1. For n = 3 as n = |a(2)|, d changes to d = -1. Therefore a(3) = a(2) + d * 3 = 0.
a(8) = -30, d = -1, and a(5) = -9. For n = 9 as n = |a(5)|, d changes to d = 1. Therefore a(9) = a(8) + d * 9 = -21.
MATHEMATICA
s = {0}; d = 1; Do[d *= If[MemberQ[s, n] || MemberQ[s, -n], -1, 1]; AppendTo[s, s[[-1]] + d*n], {n, 1, 60}]; s (* Amiram Eldar, Aug 16 2019 *)
PROG
(PARI) s=0; v=0; d=1; for (n=1, mx=60, print1 (v, ", "); if (bittest(s, n), d=-d); v+=d*n; w=abs(v); if (w<=mx, s=bitor(s, 2^w))) \\ Rémy Sigrist, Aug 16 2019
CROSSREFS
Sequence in context: A072329 A068630 A374966 * A079406 A378505 A068627
KEYWORD
sign
AUTHOR
Scott R. Shannon, Aug 15 2019
STATUS
approved