Is there any direct formula or algorithm better than the brute force (O(n) algorithm by iterating from 1 to n) way to calculate the sum


\begin{equation}
 S = \sum\limits\_{i=1}^n [{\frac{n}{i}}]
\end{equation}


where [x] denotes the integral part of x?


I tried out calculating the sum by considering i's that are factors of n.
But that does not seem to give the correct answer. Any help in any form is welcomed. 


Please point out the mistakes in tags and formatting of the question too, since I am a beginner here. 



sum of integral part of n/k
For questions like this searching for the first few terms
in OEIS might help [3, 5, 8, 10, 14, 16, 20, 23, 27, 29, 35, 37, 41](https://oeis.org/search?q=3%2C+5%2C+8%2C+10%2C+14%2C+16%2C+20%2C+23%2C+27%2C+29%2C+35%2C+37%2C+41&sort=&language=&go=Search)


This is A006218.


There are a lot of references and bounds for the sum.


In particular there is a formula $O(\sqrt{n})$:



> 
> a(n)=2\*sum(i=1, floor(sqrt(n)), floor(n/i))-floor(sqrt(n))^2 - Benoit Cloitre
> 
> 
> 


$$ a(n) = (2 \sum\_{i=1}^{\lfloor \sqrt{n} \rfloor} \lfloor n/i \rfloor) - {\lfloor \sqrt{n} \rfloor}^2 $$


Another comment:



> 
> The Polymath project (see the Tao-Croot-Helfgott link) sketches an algorithm for computing a(n) in essentially cube root time, see section 2.1
> 
> 
> 


