A079360 Sequence of sums of alternating increasing powers of 2.
1, 5, 7, 15, 19, 35, 43, 75, 91, 155, 187, 315, 379, 635, 763, 1275, 1531, 2555, 3067, 5115, 6139, 10235, 12283, 20475, 24571, 40955, 49147, 81915, 98299, 163835, 196603, 327675, 393211, 655355, 786427, 1310715, 1572859, 2621435, 3145723
Offset: 0
Links
- G. C. Greubel, Table of n, a(n) for n = 0..5000
- Tutor User "reavey" (reavey@nep.net) and others, How to write an algorithm for sequence, Tutor -- Discussion for learning programming with Python, 2003.
- Index entries for linear recurrences with constant coefficients, signature (1,2,-2).
Programs
-
GAP
a:=[1,5,7];; for n in [4..30] do a[n]:=a[n-1]+2*a[n-2]-2*a[n-3]; od; a; # G. C. Greubel, Aug 07 2019
-
Magma
I:=[1,5,7]; [n le 3 select I[n] else Self(n-1) +2*Self(n-2) -2*Self(n-3): n in [1..40]]; // G. C. Greubel, Aug 07 2019
-
Maple
seq(coeff(series((1+4*x)/((1-x)*(1-2*x^2)), x, n+1), x, n), n = 0..40); # G. C. Greubel, Aug 07 2019
-
Mathematica
LinearRecurrence[{1,2,-2}, {1,5,7}, 40] (* G. C. Greubel, Aug 07 2019 *)
-
PARI
seq(n) = { j=a=1; p=2; print1(1" "); while(j<=n, a = a + 2^p; print1(a" "); a = a+2^(p-1); print1(a" "); p+=1; j+=2; ) }
-
PARI
a(n)=if(n<0,0,(6-n%2)*2^ceil(n/2)-5)
-
Sage
@CachedFunction def a(n): if (n==0): return 1 elif (1<=n<=2): return nth_prime(n+2) else: return a(n-1) + 2*a(n-2) - 2*a(n-3) [a(n) for n in (0..40)] # G. C. Greubel, Aug 07 2019
Formula
a(2n) = 6*2^n - 5, a(2n-1) = 5*(2^n - 1). - Benoit Cloitre, Feb 16 2003
From Colin Barker, Sep 19 2012: (Start)
a(n) = a(n-1) + 2*a(n-2) - 2*a(n-3).
G.f.: (1+4*x)/((1-x)*(1-2*x^2)). (End)
Comments