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!)
A051699 Distance from n to closest prime. 28
2, 1, 0, 0, 1, 0, 1, 0, 1, 2, 1, 0, 1, 0, 1, 2, 1, 0, 1, 0, 1, 2, 1, 0, 1, 2, 3, 2, 1, 0, 1, 0, 1, 2, 3, 2, 1, 0, 1, 2, 1, 0, 1, 0, 1, 2, 1, 0, 1, 2, 3, 2, 1, 0, 1, 2, 3, 2, 1, 0, 1, 0, 1, 2, 3, 2, 1, 0, 1, 2, 1, 0, 1, 0, 1, 2, 3, 2, 1, 0, 1, 2, 1, 0, 1, 2, 3, 2, 1, 0, 1, 2, 3, 4, 3, 2, 1, 0, 1, 2, 1, 0, 1, 0, 1 (list; graph; refs; listen; history; text; internal format)
OFFSET
0,1
LINKS
Eric Weisstein's World of Mathematics, Prime Distance
FORMULA
Conjecture: S(n) = Sum_{k=1..n} a(k) is asymptotic to C*n*log(n) with C=0.29...... - Benoit Cloitre, Aug 11 2002
Comment from Giorgio Balzarotti, Sep 18 2005: by means of the Prime Number Theorem is possible to derive the following inequality: c1*n*log(n) < S(n) < c2*n*log(n), where c1 = 1/4 and c2 = 3/8 (for n > 130). For a more accurate estimation of the values for c1 and c2, it necessary to know the number of twin primes with respect to the total number of primes.
EXAMPLE
Closest primes to 0,1,2,3,4 are 2,2,2,3,3.
MAPLE
A051699 := proc(n) if isprime(n) then 0; elif n<= 2 then 2-n ; else min(nextprime(n)-n, n-prevprime(n)) ; end if ; end proc; # R. J. Mathar, Nov 01 2009
MATHEMATICA
FormatSequence[ Table[Min[Abs[n-If[n<2, 2, Prime[{#, #+1}&[PrimePi[n]]]]]], {n, 0, 101}], 51699, 0, Name->"Distance to closest prime." ]
(* From version 6 on: *) a[_?PrimeQ] = 0; a[n_] := Min[NextPrime[n]-n, n-NextPrime[n, -1]]; Table[a[n], {n, 0, 104}] (* Jean-François Alcover, Apr 05 2012 *)
PROG
(PARI) a(n)=if(n<1, 2*(n==0), vecmin(vector(n, k, abs(n-prime(k)))))
(PARI) a(n)=if(n<1, 2*(n==0), min(nextprime(n)-n, n-precprime(n)))
CROSSREFS
Sequence in context: A333816 A363709 A246398 * A328682 A007920 A127587
KEYWORD
nonn,easy,nice
AUTHOR
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 March 28 05:39 EDT 2024. Contains 371235 sequences. (Running on oeis4.)