The OEIS mourns the passing of Jim Simons and is grateful to the Simons Foundation for its support of research in many branches of science, including the OEIS.
login
The OEIS is supported by the many generous donors to the OEIS Foundation.

 

Logo
Hints
(Greetings from The On-Line Encyclopedia of Integer Sequences!)
A181482 The sum of the first n integers, with every third integer taken negative. 4

%I #92 Mar 15 2024 10:12:19

%S 1,3,0,4,9,3,10,18,9,19,30,18,31,45,30,46,63,45,64,84,63,85,108,84,

%T 109,135,108,136,165,135,166,198,165,199,234,198,235,273,234,274,315,

%U 273,316,360,315,361,408,360,409,459,408,460,513,459,514,570,513,571,630

%N The sum of the first n integers, with every third integer taken negative.

%C The partial sum for the first 10^k terms are 76, 57256, 55722556, 55572225556, 55557222255556,..., i.e., the palindrome 5{k}2{k-1}5{k} plus 1+2*10^(2*k-1). - _R. J. Cano_, Mar 10 2013, edited by _M. F. Hasler_, Mar 25 2013

%H Vincenzo Librandi, <a href="/A181482/b181482.txt">Table of n, a(n) for n = 1..1000</a>

%H Wolfram Alpha, <a href="http://www.wolframalpha.com/input/?i=Sum%5Bn*%28-1%29%5E%28%28n%2B1%29Mod3%29%2Cn%3D1..k%5D">WA Query</a>

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

%F From _R. J. Mathar_, Oct 23 2010: (Start)

%F a(n) = a(n-1) + 2*a(n-3) - 2*a(n-4) - a(n-6) + a(n-7).

%F G.f.: -x*(1+2*x+2*x^3+x^4-3*x^2) / ( (1+x+x^2)^2*(x-1)^3 ).

%F 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)

%F a(n) = sum((i+1)*A131561(i), i=0..n-1) = A000217(n)-6*A000217(floor(n/3)). [_Bruno Berselli_, Dec 10 2010]

%F a(0) = 0, a(n) = a(n-1) + (-1)^((n + 1) mod 3)*n - _Jon Perry_, Feb 17 2013

%F 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.]

%F a(3k) = 3k(k-1)/2. - _Jon Perry_, Mar 01 2013

%F a(0) = 0, a(n) = a(n-1) + (1 - ((n+1) mod 3 mod 2) * 2) * n. - _Jon Perry_, Mar 03 2013

%e a(7) = 1 + 2 - 3 + 4 + 5 - 6 + 7 = 10.

%t a[n_] := Sum[If[Mod[j, 3] == 0, -j, j], {j, 1, n}]; Table[a[i], {i, 1, 50, 1}] (* _Jon Perry_ *)

%t 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 *)

%t 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 *)

%t Table[Sum[k * (-1)^Boole[Mod[k, 3] == 0], {k, n}], {n, 60}] (* _Alonso del Arte_, Feb 24 2013 *)

%t With[{nn=20},Accumulate[Times@@@Partition[Riffle[Range[3nn],{1,1,-1}],2]]] (* _Harvey P. Dale_, Feb 09 2015 *)

%o (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

%o (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

%o (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

%o (PARI) a(n)=sum(k=1,n,k*((-1)^(k%3==0)) ) \\ _R. J. Cano_, Feb 26 2013

%o (PARI) a(n)={my(y=n\3);n*(n+1)\2-3*y*(y+1)} \\ _R. J. Cano_, Feb 28 2013

%o (Haskell)

%o a181482 n = a181482_list !! (n-1)

%o a181482_list = scanl1 (+) $ zipWith (*) [1..] $ cycle [1, 1, -1]

%o -- _Reinhard Zumkeller_, Nov 23 2014

%Y Cf. A213203, A000217.

%K nonn,easy

%O 1,2

%A _Jon Perry_, Oct 23 2010

%E More terms added by _R. J. Mathar_, Oct 23 2010

Lookup | Welcome | Wiki | Register | Music | Plot 2 | Demos | Index | Browse | More | WebCam
Contribute new seq. or comment | Format | Style Sheet | Transforms | Superseeker | Recents
The OEIS Community | Maintained by The OEIS Foundation Inc.

License Agreements, Terms of Use, Privacy Policy. .

Last modified June 10 09:13 EDT 2024. Contains 373259 sequences. (Running on oeis4.)