Reminder: The OEIS is hiring a new managing editor, and the application deadline is January 26.
%I #23 Sep 02 2024 13:04:27
%S 0,1,5,34,269,2613,28893,359110,4934952,74342563,1217389949,
%T 21533211312,409230368646,8318041706593
%N Number of n-almost primes less than or equal to n^n.
%C Consider the array T(r,c) where is the number of c-almost primes less than or equal to r^c. This is the diagonal T(r,r).
%e a(3)=5 because there are five 3-almost primes <= 27, 8,12,18,20&27.
%t AlmostPrimePi[k_Integer, n_] := Module[{a, i}, a[0] = 1; If[k == 1, PrimePi[n], 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 *)
%t Do[ Print@ AlmostPrimePi[n, n^n], {n, 13}]
%o (Python)
%o from math import isqrt, prod
%o from sympy import primerange, integer_nthroot, primepi
%o def A116435(n):
%o def almostprimepi(n,k):
%o 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)))
%o 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))
%o return almostprimepi(n**n,n) # _Chai Wah Wu_, Sep 01 2024
%Y Cf. A116433, A116434.
%K hard,more,nonn
%O 1,3
%A _Jonathan Vos Post_ and _Robert G. Wilson v_, Feb 15 2006
%E a(13)-a(14) from _Donovan Johnson_, Oct 05 2010
%E Definition of T(r,c) corrected by _R. J. Mathar_, Jun 20 2021