%I #19 Dec 01 2018 09:28:13
%S 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,
%T 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,
%U -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
%N 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.
%H Antti Karttunen, <a href="/A215029/b215029.txt">Table of n, a(n) for n = 0..20000</a>
%H Antti Karttunen, <a href="/A215029/a215029.txt">Data supplement: n, a(n) computed for n = 0..100003</a>
%H StackExchange, <a href="http://math.stackexchange.com/questions/176394/a-prime-number-pattern">A prime number pattern</a>, Jul 29 2012.
%p f:=proc(n) local m,a,i,p;
%p if n <= 2 then RETURN(n); fi;
%p m:=n; a:=n;
%p for i from 1 to n do
%p p:=prevprime(m);
%p if a>0 then a:=a-p else a:=a+p; fi;
%p m:=p;
%p if m <= 2 then RETURN(a); fi;
%p od;
%p # should never reach here
%p print("ERROR");
%p end;
%p [seq(f(i),i=0..120)];
%o (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
%Y Cf. A215030-A215035, A214912.
%K sign
%O 0,3
%A _N. J. A. Sloane_, Aug 05 2012
|