OFFSET
1,2
LINKS
G. C. Greubel, Table of n, a(n) for n = 1..1000
Index entries for linear recurrences with constant coefficients, signature (1,3,-3).
FORMULA
G.f.: x*(1+3*x-2*x^2)/((1-x)*(1-3*x^2)). - Michael Somos, Feb 18 2003
For n >= 1, a(2n-1) = (2/3)*3^n - 1, a(2n) = (5/3)*3^n - 1. - Benoit Cloitre, Feb 16 2003
MAPLE
a[1]:=1:a[2]:=4:for n from 3 to 100 do a[n]:=3*a[n-2]+2 od: seq(a[n], n=1..33); # Zerinvary Lajos, Mar 17 2008
MATHEMATICA
LinearRecurrence[{1, 3, -3}, {1, 4, 5}, 40] (* Harvey P. Dale, Oct 18 2016 *)
PROG
(PARI) a(n)=if(n<1, 0, 1+sum(k=2, n, 3^((k\2)-(k%2))))
(PARI) a(n)=if(n<0, 0, (5/3-3*n%2)*2^ceil(n/2)-1)
(Magma) I:=[1, 4, 5]; [n le 3 select I[n] else Self(n-1) +3*Self(n-2) -3*Self(n-3): n in [1..40]]; // G. C. Greubel, Aug 07 2019
(Sage)
@CachedFunction
def a(n):
if (n==0): return 1
elif (1<=n<=2): return n+3
else: return a(n-1) + 3*a(n-2) - 3*a(n-3)
[a(n) for n in (0..40)] # G. C. Greubel, Aug 07 2019
(GAP) a:=[1, 4, 5];; for n in [4..30] do a[n]:=a[n-1]+3*a[n-2]-3*a[n-3]; od; a; # G. C. Greubel, Aug 07 2019
CROSSREFS
KEYWORD
easy,nonn
AUTHOR
Cino Hilliard, Feb 15 2003
STATUS
approved