Is there a better way to get the summation of $$\sum\limits_{i=1}^n\left\lfloor\frac ni\right\rfloor$$ I would like to know a way that is better than the complexity of $O(n)$ ... because there seems to be a pattern in the way all the floor values decrease .
This is a code that does it in less than O(n) complexity but I am unable to prove it why it works
long long N;
cin >> N;
long long K = 1, mn = N, mx, sum = 0;;
while (mn > 0)
{
K = N / mn;
mx = N / K;
mn = N / (K + 1);
sum += (mx - mn)*K;
}