OFFSET
1,1
LINKS
Reinhard Zumkeller, Table of n, a(n) for n = 1..10000
FORMULA
See A045707 for comments on density of these sequences.
MATHEMATICA
Select[Table[Prime[n], {n, 3000}], First[IntegerDigits[#]]==2 &] (* Vincenzo Librandi, Aug 08 2014 *)
PROG
(Haskell)
a045708 n = a045708_list !! (n-1)
a045708_list = filter ((== 2) . a000030) a000040_list
-- Reinhard Zumkeller, Mar 16 2012
(Magma) [p: p in PrimesUpTo(2300) | Intseq(p)[#Intseq(p)] eq 2]; // Vincenzo Librandi, Aug 08 2014
(Python)
from sympy import isprime
def agen(limit=float('inf')):
yield 2
digits, adder = 1, 20
while True:
for i in range(1, 10**digits, 2):
test = adder + i
if test > limit: return
if isprime(test): yield test
digits, adder = digits+1, adder*10
agento = lambda lim: agen(limit=lim)
print(list(agento(2222))) # Michael S. Branicky, Feb 23 2021
(Python)
from sympy import primepi
def A045708(n):
def bisection(f, kmin=0, kmax=1):
while f(kmax) > kmax: kmax <<= 1
while kmax-kmin > 1:
kmid = kmax+kmin>>1
if f(kmid) <= kmid:
kmax = kmid
else:
kmin = kmid
return kmax
def f(x): return n+x+primepi(min(((m:=10**(l:=len(str(x))-1))<<1)-1, x))-primepi(min(3*m-1, x))+sum(primepi(((m:=10**i)<<1)-1)-primepi(3*m-1) for i in range(l))
return bisection(f, n, n) # Chai Wah Wu, Dec 07 2024
CROSSREFS
KEYWORD
nonn,base,easy,changed
AUTHOR
EXTENSIONS
More terms from Erich Friedman.
Offset fixed by Reinhard Zumkeller, Mar 15 2012
STATUS
approved