login
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