I am reading a text which states that $$\sum \limits_{n \leq X} \left(\log X - \log n \right) = \mathcal{O}(X)$$ I can't quite see why this is true, though I can certainly believe it. Could anyone explain how to show this?
We can rewrite this as $\displaystyle \sum_{n \leq X} \log(X/n)$, and I guess the idea behind this would be to use the fact that for "most" terms in the sum, $n \approx x$ so $\log(X/n) \approx 0$, and there are only a "few" small values of $n$ for which $\log(X/n) \approx \log(X)$. Formally proving it however, has eluded me.
To reiterate, I would like to see a proof that $$\sum_{n \leq X} \left(\log X - \log n \right) = O(X)$$
Many thanks for your help.
Hint: For simplicity let $X$ be an integer. By approximating $\log t$ by a step function, show that $$\log 1+\log 2+\cdots +\log X \ge \int_2^X \log t\,dt.$$ Then use the fact that $$\int \log t \,dt=t\log t-t.$$