Given two numbers k and n, we have to find ∑1<=i<=n(k mod i),
But it exceeds time limit, Is there a mathematical property to solve this problem in time? asked 02 Jul '13, 13:14

Conclusion: there will be at most O(Sqrt(N)) distinct values for floor(N/i). Prove: if i < sqrt(N) there will be at most sqrt(N) values if i > sqrt(N) there will be at most sqrt(N) values (because floor(N/i) < sqrt(N)) sigma K mod i = sigma K  floor(K / i) * i = N * K  sigma floor(K / i) * i we can calculate sigma floor(K / i) * i fastly for all i that floor(K / i) is the same. Here is the code
answered 04 Jul '13, 07:30

can u provide the problem link
finding total sum and then taking mod..? i guess it will work.. try this..
@kashish55 mod by what number?
there exits a sqrt(n) solution, i am formulating that solution, and will post it in a few minutes.
@darkshadows, eagerly waiting for your O(sqrt(n)) solution :)