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.

A008348 a(0)=0; thereafter a(n) = a(n-1) + prime(n) if a(n-1) < prime(n), otherwise a(n) = a(n-1) - prime(n).

This page as a plain text file.
%I A008348 #51 Sep 13 2024 15:48:41
%S A008348 0,2,5,0,7,18,5,22,3,26,55,24,61,20,63,16,69,10,71,4,75,2,81,164,75,
%T A008348 172,71,174,67,176,63,190,59,196,57,206,55,212,49,216,43,222,41,232,
%U A008348 39,236,37,248,25,252,23,256,17,258,7,264,1,270,541,264,545,262,555
%N A008348 a(0)=0; thereafter a(n) = a(n-1) + prime(n) if a(n-1) < prime(n), otherwise a(n) = a(n-1) - prime(n).
%C A008348 a(n) < 2*prime(n). Conjecture: a(n) > 0 for n > 3. - _Thomas Ordowski_, Dec 03 2016 [This conjecture is false, because a(369019)=0. The next counterexample occurs at n = 22877145. - _Dmitry Kamenetsky_, Feb 14 2017. (Cf. A309225.)]
%H A008348 Robert Israel, <a href="/A008348/b008348.txt">Table of n, a(n) for n = 0..10000</a>
%F A008348 a(n) = c(1)p(1) + ... + c(n)p(n), where c(i) = 1 if a(i-1) > p(i) and c(i) = -1 if a(i-1) <= p(i) (p(i) = primes). - _Clark Kimberling_
%p A008348 A008348 := proc(n) option remember; if n = 0 then 0 elif A008348(n-1)>=ithprime(n) then A008348(n-1)-ithprime(n); else A008348(n-1)+ithprime(n); fi; end;
%p A008348 # Maple from _N. J. A. Sloane_, Aug 31 2019 (Start)
%p A008348 # Riecaman transform
%p A008348 Riecaman := proc(a,s,M)
%p A008348 # Start with s, add or subtract a[n], get M terms. If a has w terms, can get M=w+1 terms.
%p A008348 local b,M2,n,t;
%p A008348 if whattype(a) <> list then ERROR("First argument should be a list"); fi;
%p A008348 if a[1]=0 then ERROR("a[1] should not be zero"); fi;
%p A008348 M2 := min(nops(a),M-1);
%p A008348 b:=[s]; t:=s;
%p A008348 for n from 1 to M2 do
%p A008348    if a[n]>t then t:=t+a[n] else t:=t-a[n]; fi; b:=[op(b),t]; od:
%p A008348 b; end;
%p A008348 # Riecaman transform of primes, starting at s=0
%p A008348 p1:=[seq(ithprime(i),i=1..100)];
%p A008348 q0:=Riecaman(p1,0,99);
%p A008348 # End
%t A008348 a := {0}; For[n = 2, n < 100, n++, If[a[[n - 1]] >= Prime[n - 1], b := a[[n - 1]] - Prime[n - 1], b := a[[n - 1]] + Prime[n - 1];]; a = Append[a, b]]; a (* _Stefan Steinerberger_, May 02 2006 *)
%t A008348 nxt[{n_,a_}]:={n+1,If[a<Prime[n+1],a+Prime[n+1],a-Prime[n+1]]}; NestList[nxt,{0,0},70][[;;,2]] (* _Harvey P. Dale_, Sep 13 2024 *)
%o A008348 (PARI) lista(nn) = {print1(a=0, ", "); for (n=1, nn, if (a < (p=prime(n)), a += p, a -= p); print1(a, ", "););} \\ _Michel Marcus_, Dec 04 2016
%Y A008348 Cf. A008344, A022831, A022837, A309225.
%K A008348 nonn,look
%O A008348 0,2
%A A008348 _N. J. A. Sloane_ and _J. H. Conway_
%E A008348 More terms from _Clark Kimberling_
%E A008348 Name edited by _Dmitry Kamenetsky_, Feb 14 2017