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.

A077140 a(1) = 1 and then add n to the previous term if n is coprime to the previous term, otherwise subtract n from the previous term. a(1) = 1 and a(n) = a(n-1) + n if gcd(n, a(n-1)) = 1, otherwise a(n) = a(n-1) - n.

Original entry on oeis.org

1, 3, 0, -4, 1, 7, 0, -8, 1, 11, 0, -12, 1, 15, 0, -16, 1, 19, 0, -20, 1, 23, 0, -24, 1, 27, 0, -28, 1, 31, 0, -32, 1, 35, 0, -36, 1, 39, 0, -40, 1, 43, 0, -44, 1, 47, 0, -48, 1, 51, 0, -52, 1, 55, 0
Offset: 1

Views

Author

Amarnath Murthy, Oct 30 2002

Keywords

Comments

a(2k+1) = (k+1) (mod 2), a(4k) = -4k, a(4k+2) = 4k+3. Proof: If a(4k+3)=0 then a(4k+4) = -4k-4, a(4k+5)=1, a(4k+6) = 1+4k+6 and again, a(4k+7)=0. - Ralf Stephan, Mar 18 2003
Abs(a(n)) = A003815(n). - Reinhard Zumkeller, Oct 09 2007
With different signs, it can be obtained as abs(a(n)) = abs(Sum_{i=0..n} (-1)^h(i)*i) where h(i) is the Hamming weight of i, A000120, the number of 1s in base 2. - Olivier Gérard, Jul 30 2012

Examples

			From _Ilya Gutkovskiy_, Dec 21 2015: (Start)
a(1) = 1;
a(2) = 1 + 2 = 3;
a(3) = 1 + 2 - 3 = 0;
a(4) = 1 + 2 - 3 - 4 = -4;
a(5) = 1 + 2 - 3 - 4 + 5 = 1;
a(6) = 1 + 2 - 3 - 4 + 5 + 6 = 7;
a(7) = 1 + 2 - 3 - 4 + 5 + 6 - 7 = 0;
a(8) = 1 + 2 - 3 - 4 + 5 + 6 - 7 - 8 = -8; etc. (End)
		

Crossrefs

Cf. A077141.

Programs

  • Mathematica
    CoefficientList[Series[(x^2-2x-1)/((x^2+1)^2*(x-1)),{x,0,100}],x] (* Vincenzo Librandi, Jul 30 2012 *)
    nxt[{n_,a_}]:={n+1,If[CoprimeQ[a,n+1],a+n+1,a-n-1]}; NestList[nxt,{1,1},60][[All,2]] (* Harvey P. Dale, Jul 26 2020 *)
  • PARI
    v=vector(100);v[1]=1;for(k=2,100,if(gcd(v[k-1],k)>1,v[k]=v[k-1]-k,v[k]=v[k-1]+k));print(v)

Formula

a(1) = 1 and a(n) = a(n-1) + n if gcd(n, a(n-1)) = 1, otherwise a(n) = a(n-1) - n.
G.f.: x(x^2-2x-1)/((x^2+1)^2*(x-1)). - Ralf Stephan, Mar 18 2003
Abs(a(n)) = ((n+1) mod 2)*n + (floor((n+(n mod 2))/2) mod 2). - Tj Wrenn (tjwrenn(AT)cs.utexas.edu), Apr 07 2005
a(n) = Sum_{k = 1..n} (-(-1)^((2*k - (-1)^k + 1)/4)*k). - Ilya Gutkovskiy, Dec 21 2015

Extensions

More terms from Ralf Stephan, Mar 18 2003