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.

A215029 To get a(n), start with m=n, let p = largest prime < m, set m = m-p if m>0, or m=m+p if m <= 0; repeat until p=2 has been processed; set a(n) = m.

Original entry on oeis.org

0, 1, 2, 1, -1, 0, 0, 1, 1, 2, -1, 0, 0, 1, 1, 2, -1, 0, 0, 1, 1, 2, -1, 0, 0, 1, 0, 1, 0, 1, 1, 2, 0, 1, 0, 1, 0, 1, -1, 0, 1, 2, 0, 1, -1, 0, 1, 2, 0, 1, 0, 1, 0, 1, -1, 0, 1, 2, -1, 0, 0, 1, 1, 2, -1, 0, 1, 2, 0, 1, 0, 1, -1, 0, 0, 1, 0, 1, 0, 1, 1, 2, -1, 0, 0, 1, 0, 1, 0, 1, 1, 2, -1, 0, 1, 2, -1, 0, 0, 1, 0, 1, 1, 2, 0, 1, 0, 1, -1, 0, 0, 1, 0, 1, 1
Offset: 0

Views

Author

N. J. A. Sloane, Aug 05 2012

Keywords

Crossrefs

Programs

  • Maple
    f:=proc(n) local m,a,i,p;
    if n <= 2 then RETURN(n); fi;
    m:=n; a:=n;
    for i from 1 to n do
    p:=prevprime(m);
    if a>0 then a:=a-p else a:=a+p; fi;
    m:=p;
    if m <= 2 then RETURN(a); fi;
    od;
    # should never reach here
    print("ERROR");
    end;
    [seq(f(i),i=0..120)];
  • PARI
    A215029(n) = if(n<=2,n,my(mp=precprime(n-1),d=n); while(mp>0, if(d>0, d -= mp, d += mp); mp = precprime(mp-1)); (d)); \\ Antti Karttunen, Nov 28 2018