OFFSET
1,1
COMMENTS
A227878 gives the terms occurring twice. - Reinhard Zumkeller, Oct 25 2013
LINKS
T. D. Noe, Table of n, a(n) for n = 1..1000
EXAMPLE
Closest primes to 2,3,5,7,11 are 3,2,3,5,13.
MATHEMATICA
a[n_] := (p = Prime[n]; np = NextPrime[p]; pp = NextPrime[p, -1]; If[np-p < p-pp, np, pp]); Table[a[n], {n, 1, 58}] (* Jean-François Alcover, Oct 20 2011 *)
cp[{a_, b_, c_}]:=If[c-b<b-a, c, a]; Join[{3}, cp/@Partition[Prime[Range[ 60]], 3, 1]] (* Harvey P. Dale, Oct 08 2012 *)
PROG
(Haskell)
a051701 n = a051701_list !! (n-1)
a051701_list = f 2 $ 1 : a000040_list where
f d (q:ps@(p:p':_)) = (if d <= d' then q else p') : f d' ps
where d' = p' - p
-- Reinhard Zumkeller, Oct 25 2013
(Python)
from sympy import nextprime
def aupton(terms):
prv, cur, nxt, alst = 0, 2, 3, []
while len(alst) < terms:
alst.append(prv if 2*cur - prv <= nxt else nxt)
prv, cur, nxt = cur, nxt, nextprime(nxt)
return alst
print(aupton(58)) # Michael S. Branicky, Jun 04 2021
CROSSREFS
KEYWORD
nonn,easy,nice
AUTHOR
EXTENSIONS
More terms from James A. Sellers
STATUS
approved