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.
%I A077140 #35 Jul 26 2020 17:32:20 %S A077140 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, %T A077140 -28,1,31,0,-32,1,35,0,-36,1,39,0,-40,1,43,0,-44,1,47,0,-48,1,51,0, %U A077140 -52,1,55,0 %N 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. %C A077140 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 %C A077140 Abs(a(n)) = A003815(n). - _Reinhard Zumkeller_, Oct 09 2007 %C A077140 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 %H A077140 Vincenzo Librandi, <a href="/A077140/b077140.txt">Table of n, a(n) for n = 1..1000</a> %F A077140 a(1) = 1 and a(n) = a(n-1) + n if gcd(n, a(n-1)) = 1, otherwise a(n) = a(n-1) - n. %F A077140 G.f.: x(x^2-2x-1)/((x^2+1)^2*(x-1)). - _Ralf Stephan_, Mar 18 2003 %F A077140 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 %F A077140 a(n) = Sum_{k = 1..n} (-(-1)^((2*k - (-1)^k + 1)/4)*k). - _Ilya Gutkovskiy_, Dec 21 2015 %e A077140 From _Ilya Gutkovskiy_, Dec 21 2015: (Start) %e A077140 a(1) = 1; %e A077140 a(2) = 1 + 2 = 3; %e A077140 a(3) = 1 + 2 - 3 = 0; %e A077140 a(4) = 1 + 2 - 3 - 4 = -4; %e A077140 a(5) = 1 + 2 - 3 - 4 + 5 = 1; %e A077140 a(6) = 1 + 2 - 3 - 4 + 5 + 6 = 7; %e A077140 a(7) = 1 + 2 - 3 - 4 + 5 + 6 - 7 = 0; %e A077140 a(8) = 1 + 2 - 3 - 4 + 5 + 6 - 7 - 8 = -8; etc. (End) %t A077140 CoefficientList[Series[(x^2-2x-1)/((x^2+1)^2*(x-1)),{x,0,100}],x] (* _Vincenzo Librandi_, Jul 30 2012 *) %t A077140 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 *) %o A077140 (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) %Y A077140 Cf. A077141. %K A077140 sign,easy %O A077140 1,2 %A A077140 _Amarnath Murthy_, Oct 30 2002 %E A077140 More terms from _Ralf Stephan_, Mar 18 2003