What is the order of the sum of log x?

Let

$$f(n)=\sum_{x=1}^n\log(x)$$

What is $O(f(n))$?

I know how to deal with sums of powers of $x$. But how to solve for a sum of logs?


As noted, $f(n)=\log(n!)$.

Trivially, we have $$ n!\le n^n $$

Also, using a multiplicative variant of Gauss's trick, we have: $$ (n!)^2 = (1 \cdot n) (2 \cdot (n-1)) (3 \cdot (n-2)) \cdots ((n-2) \cdot 3) ((n-1) \cdot 2) (n \cdot 1) \ge n^n $$

This implies that $$ \frac12 n \log n \le \log(n!) \le n \log n $$ and so $$ \log(n!) = \Theta(n\log n) $$


Note that the sum starts at $2$. You use the comparison with the integral: $$ \int_1^n\log x\,dx\leq\sum_{x=2}^n\log x\leq\int_2^{n+1}\log x\,dx. $$ From there you can see that $O(f(n))=n\log n$.


Using Stirling's formula we have, for $n$ sufficiently large $$ f(n)=\sum_{k=1}^n\log k=\log(n!)\simeq\log(\sqrt{2\pi}e^{-n}n^{n+1/2}). $$ Hence $$ O(f(n))=\log(\sqrt{2\pi}e^{-n}n^{n+1/2}). $$