OFFSET
0,2
LINKS
Max Alekseyev, Table of n, a(n) for n = 0..50
Eric Weisstein's World of Mathematics, Almost Prime.
FORMULA
a(n) = a(n-1) + appi3(n-k, floor(3^n/2^k)), where k = ceiling(n*c) with c = log(5/3)/log(5/2) = 0.55749295065024006729857073190835923443... and appi3(k,n) is the number of k-almost primes not divisible by 3 and not exceeding n. - Max Alekseyev, Jan 06 2008
EXAMPLE
a(3) = 5 since 3^3 is the 5th 3-almost-prime: 8,12,18,20,27,....., A014612.
MATHEMATICA
AlmostPrimePi[k_Integer /; k > 1, n_] := Module[{a, i}, a[0] = 1; Sum[PrimePi[n/Times @@ Prime[Array[a, k - 1]]] - a[k - 1] + 1, Evaluate[Sequence @@ Table[{a[i], a[i - 1], PrimePi[(n/Times @@ Prime[Array[a, i - 1]])^(1/(k - i + 1))]}, {i, k - 1}]]]]; (* Eric W. Weisstein, Feb 07 2006 *)
Table[ AlmostPrimePi[n, 3^n], {n, 2, 37}] (* Robert G. Wilson v, Feb 09 2006 *)
PROG
(PARI) a(n)=sum(i=1, 3^n, if(bigomega(i)-n, 0, 1))
(PARI)
{ appi(k, n, m=2) = local(r=0);
if(k==0, return(1));
if(k==1, return(primepi(n)));
forprime(p=m, floor(sqrtn(n, k)+1e-20),
r+=appi(k-1, n\p, p)-(k==2)*(primepi(p)-1));
r }
{ appi3(k, n) = appi(k, n) - if(k>=1, appi(k-1, n\3)) }
a=1; for(n=1, 50, k=ceil(n*log(5/3)/log(5/2)); a+=appi3(n-k, 3^n\2^k); print1(a, ", "))
\\ Max Alekseyev, Jan 06 2008
(Python)
from math import isqrt, prod
from sympy import primerange, integer_nthroot, primepi
def A078843(n):
def almostprimepi(n, k):
def g(x, a, b, c, m): yield from (((d, ) for d in enumerate(primerange(b, isqrt(x//c)+1), a)) if m==2 else (((a2, b2), )+d for a2, b2 in enumerate(primerange(b, integer_nthroot(x//c, m)[0]+1), a) for d in g(x, a2, b2, c*b2, m-1)))
return int(sum(primepi(n//prod(c[1] for c in a))-a[-1][0] for a in g(n, 0, 1, 1, k)) if k>1 else primepi(n))
return almostprimepi(3**n, n) if n else 1 # Chai Wah Wu, Sep 01 2024
CROSSREFS
KEYWORD
nonn
AUTHOR
Benoit Cloitre and Paul D. Hanna, Dec 10 2002
EXTENSIONS
a(14)-a(37) from Robert G. Wilson v, Feb 09 2006
STATUS
approved