Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 39796

How to find ∑1

$
0
0

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?


Viewing all articles
Browse latest Browse all 39796

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>