A181482 The sum of the first n integers, with every third integer taken negative.
1, 3, 0, 4, 9, 3, 10, 18, 9, 19, 30, 18, 31, 45, 30, 46, 63, 45, 64, 84, 63, 85, 108, 84, 109, 135, 108, 136, 165, 135, 166, 198, 165, 199, 234, 198, 235, 273, 234, 274, 315, 273, 316, 360, 315, 361, 408, 360, 409, 459, 408, 460, 513, 459, 514, 570, 513, 571, 630
Offset: 1
Examples
a(7) = 1 + 2 - 3 + 4 + 5 - 6 + 7 = 10.
Links
- Vincenzo Librandi, Table of n, a(n) for n = 1..1000
- Wolfram Alpha, WA Query
- Index entries for linear recurrences with constant coefficients, signature (1,0,2,-2,0,-1,1).
Programs
-
Haskell
a181482 n = a181482_list !! (n-1) a181482_list = scanl1 (+) $ zipWith (*) [1..] $ cycle [1, 1, -1] -- Reinhard Zumkeller, Nov 23 2014
-
JavaScript
c = 0; for (i = 1; i < 100; i++) {c += Math.pow(-1, (i + 1) % 3)*i; document.write(c, ", ");} // Jon Perry, Feb 17 2013
-
JavaScript
c=0; for (i = 1; i < 100; i++) { c += (1 - (i + 1) % 3 % 2 * 2) * i; document.write(c + ", "); } // Jon Perry, Mar 03 2013
-
Magma
I:=[1,3,0,4,9,3,10]; [n le 7 select I[n] else Self(n-1)+2*Self(n-3)-2*Self(n-4)-Self(n-6)+Self(n-7): n in [1..60]]; // Vincenzo Librandi, Feb 17 2013
-
Mathematica
a[n_] := Sum[If[Mod[j, 3] == 0, -j, j], {j, 1, n}]; Table[a[i], {i, 1, 50, 1}] (* Jon Perry *) tri[n_] := n (n + 1)/2; f[n_] := tri@ n - 6 tri@ Floor[n/3]; Array[f, 63] (* Robert G. Wilson v, Oct 24 2010 *) CoefficientList[Series[-(1 + 2*x + 2*x^3 + x^4 - 3*x^2)/((1 + x + x^2)^2*(x - 1)^3), {x, 0,30}], x] (* Vincenzo Librandi, Feb 17 2013 *) Table[Sum[k * (-1)^Boole[Mod[k, 3] == 0], {k, n}], {n, 60}] (* Alonso del Arte, Feb 24 2013 *) With[{nn=20},Accumulate[Times@@@Partition[Riffle[Range[3nn],{1,1,-1}],2]]] (* Harvey P. Dale, Feb 09 2015 *)
-
PARI
a(n)=sum(k=1,n,k*((-1)^(k%3==0)) ) \\ R. J. Cano, Feb 26 2013
-
PARI
a(n)={my(y=n\3);n*(n+1)\2-3*y*(y+1)} \\ R. J. Cano, Feb 28 2013
Formula
From R. J. Mathar, Oct 23 2010: (Start)
a(n) = a(n-1) + 2*a(n-3) - 2*a(n-4) - a(n-6) + a(n-7).
G.f.: -x*(1+2*x+2*x^3+x^4-3*x^2) / ( (1+x+x^2)^2*(x-1)^3 ).
a(n) = 2*A061347(n+1)/9 +4/9 + n*(n+1)/6 + 2*b(n)/3 where b(3k+1) = 0, b(3k) = -3k - 1 and b(3k+2) = 3k + 3. (End)
a(n) = sum((i+1)*A131561(i), i=0..n-1) = A000217(n)-6*A000217(floor(n/3)). [Bruno Berselli, Dec 10 2010]
a(0) = 0, a(n) = a(n-1) + (-1)^((n + 1) mod 3)*n - Jon Perry, Feb 17 2013
a(n) = n*(n+1)/2-3*floor(n/3)*(floor(n/3)+1). - R. J. Cano, Mar 01 2013 [Same as Berselli's formula. - Ed.]
a(3k) = 3k(k-1)/2. - Jon Perry, Mar 01 2013
a(0) = 0, a(n) = a(n-1) + (1 - ((n+1) mod 3 mod 2) * 2) * n. - Jon Perry, Mar 03 2013
Extensions
More terms added by R. J. Mathar, Oct 23 2010
Comments