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!)
A051697 Closest prime to n (break ties by taking the smaller prime). 23
2, 2, 2, 3, 3, 5, 5, 7, 7, 7, 11, 11, 11, 13, 13, 13, 17, 17, 17, 19, 19, 19, 23, 23, 23, 23, 23, 29, 29, 29, 29, 31, 31, 31, 31, 37, 37, 37, 37, 37, 41, 41, 41, 43, 43, 43, 47, 47, 47, 47, 47, 53, 53, 53, 53, 53, 53, 59, 59, 59, 59, 61, 61, 61, 61, 67, 67, 67, 67, 67, 71, 71 (list; graph; refs; listen; history; text; internal format)
OFFSET

0,1

LINKS

Table of n, a(n) for n=0..71.

Eric Weisstein's World of Mathematics, Nearest Prime

EXAMPLE

Closest primes to 0,1,2,3,4 are 2,2,2,3,3.

MATHEMATICA

a[n_] := (np = NextPrime[n]; pp = Prime[PrimePi[np] - 1]; Which[np > 2n-pp, pp, np < 2n-pp, np, True, pp]); a[0] = a[1] = 2; Table[a[n], {n, 0, 71}] (* Jean-Fran├žois Alcover, Jul 28 2011 *)

PROG

(PARI) a(n)=if(n<3, return(2)); my(p=precprime(n), q=nextprime(n)); if(q-n<n-p, q, p) \\ Charles R Greathouse IV, Apr 28 2015

CROSSREFS

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

Sequence in context: A224908 A029097 A210955 * A240869 A065308 A035680

Adjacent sequences:  A051694 A051695 A051696 * A051698 A051699 A051700

KEYWORD

nonn,easy

AUTHOR

N. J. A. Sloane

EXTENSIONS

More terms from James A. Sellers

STATUS

approved

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 August 18 10:19 EDT 2022. Contains 356211 sequences. (Running on oeis4.)