login

Reminder: The OEIS is hiring a new managing editor, and the application deadline is January 26.

A051700
Distance from n to closest prime that is different from n.
13
2, 1, 1, 1, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 4, 1, 2, 3, 2, 1, 2, 1, 2, 1, 2, 3, 2, 1, 4, 1, 2, 1, 2, 1, 2, 1, 2, 1, 4, 1, 2, 3, 2, 1, 6, 1, 2, 3, 2, 1, 2, 1, 2, 1, 2, 3, 2, 1, 4, 1, 2, 1, 2, 1, 2, 1, 2, 3, 2, 1, 4, 1, 2, 1, 4, 1, 2, 3, 2, 1, 6, 1, 2, 3, 4, 3, 2, 1, 4, 1, 2, 1, 2, 1, 2, 1
OFFSET
0,1
EXAMPLE
Closest primes to 0,1,2,3,4 are 2,2,3,2,3.
MAPLE
with(numtheory); f := n->min(nextprime(n)-n, n-prevprime(n));
MATHEMATICA
Table[Min[NextPrime[n]-n, n-NextPrime[n, -1]], {n, 0, 200}] (* Harvey P. Dale, Mar 27 2011 *)
CROSSREFS
KEYWORD
nonn,easy,nice
EXTENSIONS
More terms from James A. Sellers
STATUS
approved