Why doesn't Mertens's second theorem prove the Prime Number Theorem? Mertens's second theorem states that $$\sum_{p \le x} \frac 1p = \log \log x+O(1).$$ Defining $p_x=p_{\lfloor x \rfloor}$ for all real $x \ge 1$, we can replace the sum by the integral $$\int_1^x \frac 1{p_t} \; dt=\log \log x+O(1)$$ and thus $\frac 1{p_x}$ is on the order of $\frac d{dx} \log \log x=\frac 1{x \log x}$, which simplifies to the prime number theorem. This is clearly not a valid proof, but why not? I suspect that it's in the step from the integral to the expression for $\frac 1{p_x}$, but I don't see why that isn't valid.
 A: The prime number theorem, as proved by de la Vallée-Poussin, states that
\[\pi(x) = \sum_{p \leq x} 1 = \mathrm{Li}(x) + O\left(xe^{-a\sqrt{\log x}}\right),\]
where
\[\mathrm{Li}(x) = \int_2^x \frac{dt}{\log t} \sim \frac{x}{\log x}.\]
Mertens' second theorem is sometimes stated as
\[\sum_{p \leq x}\frac{1}{p} = \log \log x + M + o(1),\]
but the result that Mertens proved is actually slightly stronger, namely that there exists a constant $M$, the Meissel-Mertens constant, such that
\[\sum_{p \leq x}\frac{1}{p} = \log \log x + M + O\left(\frac{1}{\log x}\right).\]
To get from $\sum_{p \leq x} \frac{1}{p}$ to $\sum_{p \leq x} 1$, one uses partial summation, which is the rigorous way of a replacing a sum by an integral. This states that if $c_n$ is a series of complex numbers and $f(n)$ is a differentiable function, then
\[\sum_{n \leq x} c_n f(n) = C(x) f(x) - \int_{1}^{x} C(t) f'(t) \, dt,\]
where
\[C(x) = \sum_{n \leq x} c_n.\]
So if $c_n = 1/p$ if $n = p$ is a prime and $0$ otherwise, and if $f(n) = n$, then this gives
\[\sum_{p \leq x} 1 = x \sum_{p \leq x} \frac{1}{p} - \int_{e^2}^{x} \left(\sum_{p \leq t} \frac{1}{p}\right) \, dt + O(1).\]
Here I've changed the endpoints on the integral on the right-hand side, which leads to a change by a constant. Using Mertens' second theorem shows that the integral on the right-hand side is
\[\int_{e^2}^{x} \left(\sum_{p \leq t} \frac{1}{p}\right) \, dt = \int_{e^2}^{x} \log \log t \, dt + \int_{e^2}^{x} M \, dx + O\left(\int_{e^2}^{x} \frac{dt}{\log t}\right).\]
Using integration by parts, one can show that
\[\int \log \log x \, dx = x \log \log x - \mathrm{Li}(x) + C,\]
and so combining everything, we get
\[\sum_{p \leq x} 1 = x \left(\sum_{p \leq x} \frac{1}{x} - \log \log x - M\right) + O(\mathrm{Li}(x)) = O\left(\frac{x}{\log x}\right)\]
where the last step follows by Mertens' second theorem again. So we just fall short of the prime number theorem. Indeed, if we had the slightly stronger statement that
\[\sum_{p \leq x}\frac{1}{p} = \log \log x + M + o\left(\frac{1}{\log x}\right),\]
then we can use partial summation to prove the prime number theorem.
