I'm trying to sum the remainders when dividing N by numbers from $1$ up to $N$ $$\sum_{i = 1}^{N} N \bmod i$$
It's easy to write a program to evaluate the sum if N is small in $O(N)$ but what if N is large ~ 1e10
so I was wondering if there is a formula or an algorithm to get the sum in a better way than $O(N) $.
I searched online and found a paper which drives some interesting properties of the sum yet doesn't state an efficient way to compute it although it contains a recursive formula yet that formula isn't practical since it reduced the problem from $N$ to $N-1$ and the relationship contains $\sigma (n)$ which can be evaluated at best in $O$(#prime factors of $N$) resulting in a much worse time than $O(N)$
on the other hand the paper contains the formula $$ \sum_{i = 1}^{N} N \bmod i = N^{2} - \sum_{i = 1}^{N} \sigma (i) $$
so if I can evaluate the sum of the sum-of-divisors function I would get the answer, yet I searched online and found only this discussion which had a formula for the sum of the sum-of-divisors function yet it's not exact and contains the sum of fractions which introduce rounding errors
so I was wondering if there is a way to evaluate any of the two sums exactly and in a better time complexity than $O(N)$.