login

Year-end appeal: Please make a donation to the OEIS Foundation to support ongoing development and maintenance of the OEIS. We are now in our 61st year, we have over 378,000 sequences, and we’ve reached 11,000 citations (which often say “discovered thanks to the OEIS”).

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.
9
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,3
LINKS
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)];
PROG
(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
CROSSREFS
KEYWORD
sign
AUTHOR
N. J. A. Sloane, Aug 05 2012
STATUS
approved