OFFSET
0,2
COMMENTS
Apart from the first nonzero term the sequence is identical to A036352. - Hugo Pfoertner, Jul 22 2003
LINKS
Eric Weisstein's World of Mathematics, Semiprime
FORMULA
(1/2)*( pi(10^(n/2)) + Sum_{i=1..pi(10^n)} pi( (10^n-1)/P_i) ) = Sum_{i=1..pi(sqrt(10^n))} pi( (10^n-1)/P_i ) - binomial( pi(sqrt(10^n)), 2). - Robert G. Wilson v, May 16 2005
EXAMPLE
Below 10 there are three semiprimes: 4 (2*2), 6 (2*3) and 9 (3*3).
MATHEMATICA
f[n_] := Sum[ PrimePi[(10^n - 1)/Prime[i]], {i, PrimePi[ Sqrt[10^n]]}] - Binomial[ PrimePi[ Sqrt[10^n]], 2]; Do[ Print[ f[n]], {n, 0, 14}] (* Robert G. Wilson v, May 16 2005 *)
SemiPrimePi[n_] := Sum[ PrimePi[n/Prime@ i] - i + 1, {i, PrimePi@ Sqrt@ n}]; Array[ SemiPrimePi[10^# - 1] &, 14, 0] (* Robert G. Wilson v, Jan 21 2015 *)
PROG
(PARI) a(n)=my(s); forprime(p=2, sqrt(10^n), s+=primepi((10^n-1)\p)); s-binomial(primepi(sqrt(10^n)), 2) \\ Charles R Greathouse IV, Apr 23 2012
(Perl) use Math::Prime::Util qw/:all/; use integer; sub countsp { my($k, $sum, $pc)=($_[0]-1, 0, 1); prime_precalc(60_000_000); forprimes { $sum += prime_count($k/$_) + 1 - $pc++; } int(sqrt($k)); $sum; } foreach my $n (0..16) { say "$n: ", countsp(10**$n); } # Dana Jacobsen, May 11 2014
(Python)
from math import isqrt
from sympy import primepi, primerange
def A066265(n): return int((-(t:=primepi(s:=isqrt(m:=10**n)))*(t-1)>>1)+sum(primepi(m//k) for k in primerange(1, s+1))) if n>1 else 3*n # Chai Wah Wu, Aug 16 2024
CROSSREFS
KEYWORD
nonn,changed
AUTHOR
Patrick De Geest, Dec 10 2001
EXTENSIONS
More terms from Hugo Pfoertner, Jul 22 2003
a(14) from Robert G. Wilson v, May 16 2005
a(15)-a(16) from Donovan Johnson, Mar 18 2010
a(17)-a(18) from Dana Jacobsen, May 11 2014
a(19)-a(21) from Henri Lifchitz, Jul 04 2015
a(22)-a(23) from Henri Lifchitz, Nov 09 2024
STATUS
approved