OFFSET
0,3
LINKS
Antti Karttunen, Table of n, a(n) for n = 0..20000
Antti Karttunen, Data supplement: n, a(n) computed for n = 0..100003
StackExchange, A prime number pattern, Jul 29 2012.
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