I'm reading a book which gives a recipe of sorts to derive the approximations: $$\ln(n!) = \sum_{m=1}^{n} \ln m= n\ln n -n + O(\ln n)$$ I get stuck towards the end of the derivation, here goes:
for $m\ge1$, we have
$$0 \le \int_m^{m+1}\ln x\, dx - \ln m = \int_m^{m+1}\ln \frac{x}{m}\, dx \le \int_m^{m+1}\frac{x}{m}-1\, dx = \frac{1}{2m}$$
So far so good. Now we're told to sum for $m = 1, 2, ... n-1$, and use the fact that primitive of $\ln x$ is $x\ln x - x$. Let's go ahead and do that; by summing we get:
$$0\le\int_{1}^{n} \ln x\,dx - \sum_{m=1}^{n-1} \ln m \le \frac{1}{2} \sum_{m=1}^{n-1}\frac{1}{m} $$ and simplifying the integral:
$$0\le n\ln n - n + 1 - \sum_{m=1}^{n-1} \ln m \le \frac{1}{2} \sum_{m=1}^{n-1}\frac{1}{m} $$
This is where the instructions stop. Now it feels like we are very close to the result, however I'm unable to conclude. I tried to use the fact that $$\sum_{m=1}^{n-1}\frac{1}{m} \le 1 + \ln(n-1)$$ but to no avail. The problem seems to be that our sums go to $n-1$ but we always have $n\ln n - n$ (Though we do seem to be getting the $n-1$). Any step in the right direction is welcome.
EDIT It took a while but I did get it in the end. $$0\le n\ln n - n + 1 - \sum_{m=1}^{n-1} \ln m \le \frac{1}{2} (1+\ln (n-1)) $$ $$0\le n\ln n - n + 1 - \sum_{m=1}^{n-1} \ln m \le 1 + \ln (n-1) $$ $$-1 \le n\ln n - n - \sum_{m=1}^{n-1} \ln m \le \ln (n-1) \le \ln(n)$$ $$-1 - \ln(n) \le n\ln n - n - \sum_{m=1}^{n} \ln m \le 0$$
and finally for $n\ge2$, $1 \le 2\ln 2$, so $$-3\ln(n) \le n\ln n - n - \sum_{m=1}^{n} \ln m \le 0$$.
We can happily conclude :
$$\left|n\ln n - n - \sum_{m=1}^{n} \ln m \right| \le 3\ln n$$
Hence $$\ln(n!) = n\ln n -n + O(\ln n)$$
I'm unsure what to do about a question which I've managed to answer so I'll leave it up here.