A166597 Let p = largest prime <= n, with p(0)=p(1)=0, and let q = smallest prime > n; then a(n) = q-p.
2, 2, 1, 2, 2, 2, 2, 4, 4, 4, 4, 2, 2, 4, 4, 4, 4, 2, 2, 4, 4, 4, 4, 6, 6, 6, 6, 6, 6, 2, 2, 6, 6, 6, 6, 6, 6, 4, 4, 4, 4, 2, 2, 4, 4, 4, 4, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 2, 2, 6, 6, 6, 6, 6, 6, 4, 4, 4, 4, 2, 2, 6, 6, 6, 6, 6, 6, 4, 4, 4, 4, 6, 6, 6, 6, 6, 6, 8, 8, 8, 8, 8, 8, 8, 8, 4, 4, 4, 4, 2, 2, 4, 4
Offset: 0
Keywords
Examples
a(0) = 2 since the least prime greater than 0 is 2 (gap of 2 from 0 to 2). a(9) = 4 since the least prime greater than 9 is 11 (gap of 4 from 7 to 11). a(11) = 2 since the least prime greater than 11 is 13 (gap of 2 from 11 to 13).
Links
- Daniel Forgues, Table of n, a(n) for n = 0..100000
- Eric Weisstein's World of Mathematics, Prime Gaps.
- Eric Weisstein's World of Mathematics, Cramer-Granville Conjecture.
- Eric Weisstein's World of Mathematics, Shanks Conjecture.
Crossrefs
Programs
-
Maple
2,2,seq(nextprime(n)-prevprime(n+1), n=2..100); # Ridouane Oudra, Dec 28 2024
-
Mathematica
f[n_]:=Module[{a=If[PrimeQ[n],n,NextPrime[n,-1]]}, NextPrime[n]-a]; Join[{2,2},Array[f,120,2]] (* Harvey P. Dale, May 17 2011 *)
-
PARI
a(n) = nextprime(n+1) - precprime(n); \\ Michel Marcus, Mar 02 2023
Formula
Extensions
Definition rephrased by N. J. A. Sloane, Oct 25 2009
Comments