login
a(n) = least k >= 0 such that (n+k)/2 is prime.
2

%I #10 Oct 13 2019 10:21:51

%S 4,3,2,1,0,1,0,3,2,1,0,3,2,1,0,7,6,5,4,3,2,1,0,3,2,1,0,7,6,5,4,3,2,1,

%T 0,3,2,1,0,7,6,5,4,3,2,1,0,11,10,9,8,7,6,5,4,3,2,1,0,3,2,1,0,11,10,9,

%U 8,7,6,5,4,3,2,1,0,7,6,5,4,3,2,1,0,3,2,1,0,7,6,5,4,3,2,1,0,11,10,9,8,7,6,5

%N a(n) = least k >= 0 such that (n+k)/2 is prime.

%C If a(n) = k is nonzero then a(n+1) = k-1. a(2p) = 0 for p prime.

%H Harvey P. Dale, <a href="/A100802/b100802.txt">Table of n, a(n) for n = 0..1000</a>

%t a = {}; Do[k = 0; While[ ! PrimeQ[(n + k)/2], k++ ]; AppendTo[a, k];, {n, 0, 120}]; a (* _Ray Chandler_, Jan 19 2005 *)

%t lk[n_]:=Module[{k=If[EvenQ[n],0,1]},While[!PrimeQ[(n+k)/2],k=k+2];k]; Array[lk,120,0] (* _Harvey P. Dale_, Nov 25 2016 *)

%Y Cf. A100803.

%K nonn,easy

%O 0,1

%A _Amarnath Murthy_, Dec 18 2004

%E Extended by _Ray Chandler_, Jan 19 2005