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”).

Distance from n-th prime to closest prime.
19

%I #17 Feb 06 2017 22:01:40

%S 1,1,2,2,2,2,2,2,4,2,2,4,2,2,4,6,2,2,4,2,2,4,4,6,4,2,2,2,2,4,4,4,2,2,

%T 2,2,6,4,4,6,2,2,2,2,2,2,12,4,2,2,4,2,2,6,6,6,2,2,4,2,2,10,4,2,2,4,6,

%U 6,2,2,4,6,6,6,4,4,6,4,4,8,2,2,2,2,4,4,6,4,2,2,4,8,4,4,4,4,6,2,2,6,6,6,6,2

%N Distance from n-th prime to closest prime.

%H T. D. Noe, <a href="/A051702/b051702.txt">Table of n, a(n) for n = 1..10000</a>

%e Closest primes to 2,3,5,7,11 are 3,2,3,5,13.

%t a[n_] := Min[(p = Prime[n]) - NextPrime[p, -1], NextPrime[p] - p]; Table[a[n], {n, 1, 104}] (* _Jean-François Alcover_, May 27 2013 *)

%t Join[{1},Min[Differences[#]]&/@Partition[Prime[Range[110]],3,1]] (* _Harvey P. Dale_, Sep 23 2016 *)

%o (PARI) a(n,p=prime(n))=min(p-precprime(p-1),nextprime(p+1)-p) \\ _Charles R Greathouse IV_, Feb 06 2017

%Y Related sequences: A023186-A023188, A046929-A046931, A051650, A051652, A051697-A051702, A051728-A051730.

%Y A046929(n+1) + 1.

%K nonn,easy,nice

%O 1,3

%A _N. J. A. Sloane_

%E More terms from _James A. Sellers_