Solution (source code)

= Solution

Let $p_1,\ldots,p_a$ be the <primes> not exceeding $\sqrt x$, where $a=\pi(\sqrt x)$, and let $\Phi(x,a)$ count integers $1\leq n\leq x$ divisible by none of these primes. Every surviving integer other than $1$ is prime: a composite integer at most $x$ has a prime factor at most its square root. Conversely, the surviving primes are exactly those between $\sqrt x$ and $x$. Thus the <Legendre prime-counting formula> is
$$
\boxed{\pi(x)=\Phi(x,\pi(\sqrt x))+\pi(\sqrt x)-1\quad(x\geq1).}
$$
By <inclusion-exclusion>,
$$
\Phi(x,a)=\sum_{S\subseteq\{1,\ldots,a\}}(-1)^{|S|}
\left\lfloor\frac{x}{\prod_{i\in S}p_i}\right\rfloor,
$$
where the empty product is one. To cover literally every positive real $x$, replace the subtraction of $1$ by $\mathbf1_{\{x\geq1\}}$: for $0<x<1$, both counts are zero and there is no surviving integer $1$.

For $x=48$, the sieving primes are $2,3,5$. The surviving count is $48-(24+16+9)+(8+4+3)-1=13$. Consequently
$$
\boxed{\pi(48)=13+3-1=15.}
$$