login
a(0) = 0; thereafter a(n) = a(n-1)/2 + n if a(n-1) is even, otherwise a(n) = a(n-1) + a(n-2).
2

%I #63 Apr 05 2022 10:50:29

%S 0,1,1,2,5,7,12,13,25,38,29,67,96,61,157,218,125,343,468,253,721,974,

%T 509,1483,1992,1021,3013,4034,2045,6079,8124,4093,12217,16310,8189,

%U 24499,32688,16381,49069,65450,32765,98215,130980,65533,196513,262046,131069,393115,524184

%N a(0) = 0; thereafter a(n) = a(n-1)/2 + n if a(n-1) is even, otherwise a(n) = a(n-1) + a(n-2).

%C Terms are even if and only if n is a multiple of 3. This can be shown by induction. The predictable pattern means the sequence is given by a linear recurrence with constant coefficients. - _Andrew Howroyd_, Dec 15 2021

%H Ben Whitmore, <a href="/A350129/b350129.txt">Table of n, a(n) for n = 0..1000</a>

%H <a href="/index/Rec#order_09">Index entries for linear recurrences with constant coefficients</a>, signature (0,0,4,0,0,-5,0,0,2).

%F G.f.: x*(1 + 2*x^3)*(1 + x + 2*x^2 - x^3 + x^4)/((1 - x)^2*(1 + x + x^2)^2*(1 - 2*x^3)). - _Andrew Howroyd_, Dec 15 2021

%F From _Ben Whitmore_, Dec 17 2021: (Start)

%F a(n) = 2^(n/3+3)-2n-8 if n == 0 (mod 3);

%F a(n) = 2^((n+5)/3)-3 if n == 1 (mod 3);

%F a(n) = 3*2^((n+4)/3)-2n-7 if n == 2 (mod 3).

%F (End)

%e Start at a(0)=0.

%e 0 is even, so to get a(1), divide by 2 and add n: a(1) = 0/2 + 1 = 1.

%e 1 is odd, so to get a(2), add the previous term: a(2) = a(1) + a(0) = 1 + 1 = 1.

%e Continuing, we get

%e n a(n)

%e - ----

%e 0 0

%e 1 0/2 = 0 + 1 = 1

%e 2 1 + 0 = 1

%e 3 1 + 1 = 2

%e 4 2/2 = 1 + 4 = 5

%e 5 5 + 2 = 7

%e 6 7 + 5 = 12

%e 7 12/2 = 6 + 7 = 13

%t a[0] = 0; a[n_] := a[n] = If[EvenQ[a[n - 1]], a[n - 1]/2 + n, a[n - 1] + a[n - 2]]; Array[a, 50, 0] (* _Amiram Eldar_, Dec 15 2021 *)

%o (Python)

%o a = [0]

%o [a.append(a[-1] + a[-2] if a[-1]%2 else a[-1]//2 + n) for n in range(1, 49)]

%o print(a) # _Michael S. Branicky_, Dec 15 2021

%o (PARI) seq(n)={my(a=vector(n)); a[1]=0; for(n=2, #a, a[n] = if(a[n-1]%2==0, a[n-1]/2+(n-1), a[n-1]+a[n-2])); a} \\ _Andrew Howroyd_, Dec 15 2021

%o (PARI) concat([0], Vec((1 + 2*x^3)*(1 + x + 2*x^2 - x^3 + x^4)/((1 - x)^2*(1 + x + x^2)^2*(1 - 2*x^3)) + O(x^30))) \\ _Andrew Howroyd_, Dec 15 2021

%K nonn,easy

%O 0,4

%A _Gavin Lupo_, Dec 15 2021