# Can you derive a formula for the semiprime counting function from the prime number theorem?

E.g., there are $4$ semiprimes less than or equal to $10$ $(4, 6, 9, 10)$ or $2$ squarefree semiprimes ($6$ and $10$).

It's ok if it's off for small numbers but gets more accurate as $n \to \infty$.

Asymptotically there are about $n\frac{\log\log n}{\log n}$ semiprimes up to $n$, almost all of which are squarefree.
There's also an exact formula if you know all the primes up to the square root of $n$: $$-{\pi\left(\sqrt{n}\right)\choose 2}+\sum_{p^2\le n} \pi\left(\frac{n}{p}\right)$$ for all semiprimes, or $$-{\pi\left(\sqrt{n}\right)\choose 2}-\pi\left(\sqrt{n}\right)+\sum_{p^2\le n} \pi\left(\frac{n}{p}\right)$$ for the squarefree semiprimes only.
• Where did you find the exact formulas? Also do you happen to know if they can be extended to numbers of the form $n=p_1p_2p_3$ squarefree? Feb 1 '15 at 15:29
Redesignate the prime counting function as $p_1(x)$, which counts how many numbers between 0 and $x$ have one prime factor (provided $x$ is a nonnegative real number). Then, given $k \in \mathbb{Z}^+$, we have $$\pi_k(x) \sim \frac{x}{\log x} \frac{(\log \log x)^{k - 1}}{(k - 1)!}.$$ Setting $k = 2$ gives us $$\pi_2(x) \sim \frac{x \log \log x}{\log x}.$$ This comes from Landau's Handbuch der Lehre von der Verteilung der Primzahlen. It is way off at first, it says there are $-2$ semiprimes between 0 and 2.