[go: up one dir, main page]

login
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

%I #38 Aug 21 2019 14:58:41

%S 0,1,3,0,-4,-9,-15,-22,-30,-21,-11,-22,-34,-47,-61,-46,-30,-13,5,24,

%T 44,23,45,22,46,71,97,124,152,181,151,120,88,55,89,124,160,197,235,

%U 274,314,355,397,440,396,441,395,442,490,539,589,640,692,745,799,744,688,631,573,514

%N 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.

%C 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.

%H Scott R. Shannon, <a href="/A309764/b309764.txt">Table of n, a(n) for n = 1..20000</a>

%H Scott R. Shannon, <a href="/A309764/a309764.java.txt">Java program to produce the sequence</a>.

%e 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.

%e 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.

%t 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 *)

%o (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

%Y Cf. A005132, A079406.

%K sign

%O 0,3

%A _Scott R. Shannon_, Aug 15 2019