OFFSET
1,1
LINKS
Kim Walisch, primecount.
FORMULA
a(n) = prime(floor(A006880(n) / 2) + 1). - David A. Corneth, Mar 19 2019
EXAMPLE
From David A. Corneth, Mar 19 2019: (Start)
There are 25 primes <= 10^2 = 100 so a(2) is the (25 + 1)/2 = 13th prime, being 41.
There are 168 primes <= 10^3 = 1000 so a(3) is the prime closest to the average of prime(84) = 433 and prime(85) = 439. That average is 436, equally distant from both primes. So the largest is chosen. This disables the need to compute the median and we can immediately say that a(3) = prime(168 / 2 + 1) = 439. (End)
MATHEMATICA
a[n_] := Prime[Floor[PrimePi[10^n]/2] + 1]; Array[a, 10] (* Amiram Eldar, Mar 20 2019 *)
PROG
(Julia) using Statistics, Primes
function MedianPrimes(n)
med = Int64(round(median(primes(10^n))))
isprime(med) && return med
prevmed = prevprime(med); nextmed = nextprime(med)
abs(med - prevmed) < abs(med - nextmed) ? prevmed : nextmed end
println([MedianPrimes(n) for n in 1:12])
(PARI) a(n) = pi = primepi(10^n); prime(pi \ 2 + 1) \\ David A. Corneth, Mar 19 2019
CROSSREFS
KEYWORD
nonn,more
AUTHOR
Peter Luschny, Mar 19 2019
EXTENSIONS
a(11) from David A. Corneth, Mar 19 2019
a(12)-a(19) using Kim Walisch's primecount, from Amiram Eldar, Mar 20 2019
a(20) from Jinyuan Wang, Nov 14 2020
STATUS
approved