Given two numbers k and n, we have to find ∑1<=i<=n(k mod i),
Constraints n>=1 n < k<=10^9
time limit- 1s
obvious approach is
r = 0;
for i from 1 to n do
r += (k mod i);
return r
But it exceeds time limit, Is there a mathematical property to solve this problem in time?