login
a(n) = n*(n+1)/2 if n is odd, otherwise (n-1)*n/2 + 1.
7

%I #36 May 24 2022 10:00:21

%S 1,1,2,6,7,15,16,28,29,45,46,66,67,91,92,120,121,153,154,190,191,231,

%T 232,276,277,325,326,378,379,435,436,496,497,561,562,630,631,703,704,

%U 780,781,861,862,946,947,1035,1036,1128,1129,1225,1226,1326,1327,1431,1432,1540

%N a(n) = n*(n+1)/2 if n is odd, otherwise (n-1)*n/2 + 1.

%H Reinhard Zumkeller, <a href="/A128918/b128918.txt">Table of n, a(n) for n = 0..10000</a>

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

%F a(n) = a(n-1) + 2*a(n-2) - 2*a(n-3) - a(n-4) + a(n-5), with a(0)=1, a(1)=1, a(2)=2, a(3)=6, a(4)=7. - _Harvey P. Dale_, Mar 31 2012

%F a(n) = (1/2)*(-1)^n*(n+(-1)^n*((n-2)*n+2)-2). - _Harvey P. Dale_, Mar 31 2012

%F a(2*n) = A130883(n); a(2*n+1) = A000384(n+1). - _Reinhard Zumkeller_, Oct 12 2013

%F G.f.: (1 - x^2 + 4*x^3) / ((1 - x)^3*(1 + x)^2). - _Colin Barker_, Jan 20 2018

%p A128918:=n->`if`((n mod 2) = 1, n*(n+1)/2, (n-1)*n/2+1): seq(A128918(n), n=0..100); # _Wesley Ivan Hurt_, Feb 03 2017

%t Table[If[OddQ[n],(n(n+1))/2,(n(n-1))/2+1],{n,0,60}] (* or *)

%t LinearRecurrence[{1,2,-2,-1,1},{1,1,2,6,7},60] (* _Harvey P. Dale_, Mar 31 2012 *)

%t CoefficientList[ Series[(-4x^3 + x^2 -1)/((x -1)^3 (x + 1)^2), {x, 0, 55}], x] (* _Robert G. Wilson v_, Jan 20 2018 *)

%o (Haskell)

%o a128918 n = (n + m - 1) * n' + m * n - m + 1 where (n', m) = divMod n 2

%o -- _Reinhard Zumkeller_, Oct 12 2013

%o (PARI) a(n)=if(n%2,n*(n+1),(n-1)*n+2)/2 \\ _Charles R Greathouse IV_, Oct 16 2015

%o (PARI) Vec((1 - x^2 + 4*x^3) / ((1 - x)^3*(1 + x)^2) + O(x^40)) \\ _Colin Barker_, Jan 20 2018

%o (Python)

%o def A128918(n): return n*(n-1)//2 + 1 + (n-1)*(n%2) # _Chai Wah Wu_, May 24 2022

%Y Cf. A000384, A130883, A131179.

%K nonn,easy

%O 0,3

%A _N. J. A. Sloane_, Sep 26 2007