cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

A140756 Count up to k sequence with alternating signs (k always positive).

Original entry on oeis.org

1, -1, 2, 1, -2, 3, -1, 2, -3, 4, 1, -2, 3, -4, 5, -1, 2, -3, 4, -5, 6, 1, -2, 3, -4, 5, -6, 7, -1, 2, -3, 4, -5, 6, -7, 8, 1, -2, 3, -4, 5, -6, 7, -8, 9, -1, 2, -3, 4, -5, 6, -7, 8, -9, 10, 1, -2, 3, -4, 5, -6, 7, -8, 9, -10, 11, -1, 2, -3, 4, -5, 6, -7, 8, -9, 10, -11, 12, 1, -2, 3, -4, 5, -6, 7, -8, 9, -10, 11, -12, 13
Offset: 1

Views

Author

Keywords

Comments

Row sums are A004526(n+1).

Examples

			Triangle begins:
   1;
  -1,  2;
   1, -2,  3;
  -1,  2, -3,  4;
   1, -2,  3, -4,  5;
  -1,  2, -3,  4, -5,  6;
		

Crossrefs

Programs

  • Magma
    [(-1)^(n+k)*k: k in [1..n], n in [1..12]]; // G. C. Greubel, Oct 21 2023
    
  • Mathematica
    a[n_]:= With[{t=Floor[(-1+Sqrt[8*n-7])/2]}, (-1)^(Binomial[t+2,2] -n)*(n-Binomial[t+1,2])];
    Table[a[n], {n,100}] (* G. C. Greubel, Oct 21 2023 *)
  • Python
    from math import comb, isqrt
    def A140756(n): return comb(r,2)-n if comb((r:=(m:=isqrt(k:=n<<1))+(k>m*(m+1)))+1,2)-n&1 else n-comb(r,2) # Chai Wah Wu, Jun 09 2025
  • SageMath
    flatten([[(-1)^(n+k)*k for k in range(1,n+1)] for n in range(1,13)]) # G. C. Greubel, Oct 21 2023
    

Formula

Regarded as a triangle, T(n,k) = (-1)^{n-k} * k.
From Boris Putievskiy, Mar 14 2013: (Start)
a(n) = (-1)^(A004736(n) + 1) * A002260(n).
a(n) = (-1)^(j+1) * i, where i = n - t*(t+1)/2, j = (t^2 + 3*t + 4)/2 -n, and t = floor((-1 + sqrt(8*n-7))/2). (End)