OFFSET
1,1
COMMENTS
Lim_{n->infinity} a(n)/10^(n-1) = Pi.
Demonstration: If gap_a(p) (resp. gap_b(p)) denotes the gap between a prime p and the next (resp. preceding) prime, we have by definition |Pi*10^(n-1)-a(n)| < max(gap_a(a(n)),gap_b(a(n)))/2. Now, it is known from results on prime gaps (e.g., Ingham, 1937) that gap_a(p) and gap_b(p) are O(p^theta) for some theta < 1; thus |Pi*10^(n-1)-a(n)| = O(a(n)^theta) and the result.
LINKS
Alois P. Heinz, Table of n, a(n) for n = 1..300
MAPLE
a:= proc(n) local f, h, p, q; Digits:= 20+n;
f:= evalf(Pi*10^(n-1)); h:= round(f);
if isprime(h) then return h fi;
p:= prevprime(h); q:= nextprime(h);
`if`(f-p < q-f, p, q)
end:
seq(a(n), n=1..30); # Alois P. Heinz, Sep 24 2014
MATHEMATICA
a[n_]:=If[10^(n-1)*Pi<1/2(NextPrime[10^(n-1)*Pi, -1]+NextPrime[10^(n-1)*Pi]), NextPrime[10^(n-1)*Pi, -1], NextPrime[10^(n-1)*Pi]]; Table[a[n], {n, 20}] (* Farideh Firoozbakht, Sep 18 2014, Sep 24 2014 *)
np[n_]:=With[{c=Pi 10^n}, Nearest[{NextPrime[c, -1], NextPrime[c]}, c]]; Array[np, 20, 0]//Flatten (* Harvey P. Dale, Feb 01 2024 *)
PROG
(Python)
from sympy import isprime, nextprime, prevprime, S
def a(n):
target = int(S.Pi*10**(n-1))
if isprime(target): return target
before, after = prevprime(target), nextprime(target)
return before if target-before <= after-target else after
print([a(n) for n in range(1, 21)]) # Michael S. Branicky, Mar 31 2021
CROSSREFS
KEYWORD
nonn
AUTHOR
Jean-Christophe Hervé, Sep 18 2014
EXTENSIONS
a(7)-a(14) from Farideh Firoozbakht, Sep 18 2014
a(15)-a(20) from Alois P. Heinz, Sep 24 2014
STATUS
approved