Re: [algogeeks] Need an optimized solution.

2013-10-18 Thread Saurabh Paliwal
there is a minor correction in definition of r, actually r is the maximum of all the numbers i such that *i*k-1<=n.* On Fri, Oct 18, 2013 at 2:38 PM, Saurabh Paliwal < saurabh.paliwa...@gmail.com> wrote: > I think I have an O(1) solution to this problem. > > I think we can use the idea of summin

Re: [algogeeks] Need an optimized solution.

2013-10-18 Thread Saurabh Paliwal
I think I have an O(1) solution to this problem. I think we can use the idea of summing the pairs of all the values which are divisible by k. The answer will have r+1 terms ( I define r below ) Term 1 : floor((k-1)/2) will give us the value of pairs who have sum k. Term 2 : floor((2*k-1)/2) will