login
The OEIS is supported by the many generous donors to the OEIS Foundation.

 

Logo
Hints
(Greetings from The On-Line Encyclopedia of Integer Sequences!)
A051652 Smallest number at distance n from nearest prime. 19

%I #33 Mar 03 2021 02:36:59

%S 2,1,0,26,23,118,53,120,409,532,293,1140,211,1340,1341,1342,1343,1344,

%T 2179,15702,3967,15704,15705,19632,16033,19634,19635,31424,31425,

%U 31426,24281,31428,31429,31430,31431,31432,31433,155958,155959,155960,38501

%N Smallest number at distance n from nearest prime.

%H Michael S. Branicky, <a href="/A051652/b051652.txt">Table of n, a(n) for n = 0..228</a> (terms 0..91 from _R. J. Mathar_)

%H Michael S. Branicky, <a href="/A051652/a051652.py.txt">Python program</a>

%p A051700 := proc(m) option remember ; if m <= 2 then op(m+1,[2,1,1]) ; else min(nextprime(m)-m,m-prevprime(m)) ; fi ; end:

%p A051652 := proc(n) local m ; if n = 0 then RETURN(2); else for m from 0 do if A051700(m) = n then RETURN(m) ; fi ; od: fi ; end:

%p for n from 0 to 79 do printf("%d %d\n",n,A051652(n)); od: # _R. J. Mathar_, Jul 22 2009

%t A051700[n_] := A051700[n] = Min[ NextPrime[n] - n, n - NextPrime[n, -1]]; a[n_] := For[m = 0, True, m++, If[A051700[m] == n, Return[m]]]; a[0] = 2; Table[ a[n], {n, 0, 40}] (* _Jean-François Alcover_, Dec 19 2011, after _R. J. Mathar_ *)

%t Join[{2,1,0},Drop[Flatten[Table[Position[Table[Min[NextPrime[n]-n, n-NextPrime[ n,-1]],{n,200000}],_?(#==i&),{1},1],{i,40}]],2]] (* _Harvey P. Dale_, Mar 16 2015 *)

%o (Python) # see link for faster program

%o from sympy import prevprime, nextprime

%o def A051700(n):

%o return [2, 1, 1][n] if n < 3 else min(n-prevprime(n), nextprime(n)-n)

%o def a(n):

%o if n == 0: return 2

%o m = 0

%o while A051700(m) != n: m += 1

%o return m

%o print([a(n) for n in range(26)]) # _Michael S. Branicky_, Feb 27 2021

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

%K nonn,nice

%O 0,1

%A _N. J. A. Sloane_

%E More terms from _James A. Sellers_, Dec 07 1999

Lookup | Welcome | Wiki | Register | Music | Plot 2 | Demos | Index | Browse | More | WebCam
Contribute new seq. or comment | Format | Style Sheet | Transforms | Superseeker | Recents
The OEIS Community | Maintained by The OEIS Foundation Inc.

License Agreements, Terms of Use, Privacy Policy. .

Last modified April 25 03:15 EDT 2024. Contains 371964 sequences. (Running on oeis4.)