sory fr prev wrng cmnt

On Mon, Jul 30, 2012 at 4:04 PM, SHOBHIT GUPTA
<shobhitgupta1...@gmail.com>wrote:

> wat abt 32
>
>
> On Mon, Jul 30, 2012 at 4:02 PM, Lucifer <sourabhd2...@gmail.com> wrote:
>
>> @ ruru
>> I think we can do it in log(n)..
>> I am not jolting down the code but giving out the idea that would lead
>> to log(n) time..
>>
>> If we write down all the nos. in the binary format one below the
>> other.. we will observe the following pattern :-
>>
>> at bit index '1' the bit value toggles in group of '01'
>> at bit index '2' the bit value toggles in group of '0011' ans so on..
>>
>> Hence using basic divisibility property we can calculate the no. of
>> one's at every it index 'i' where 'i' ranges from 1 to log(N)..
>>
>>
>> On 30 July, 15:25, Zyro <vivkum...@gmail.com> wrote:
>> > int func(int start,int end)
>> > {
>> >    int count=0;
>> >    for(int i=start;i<=end;i++)
>> >     {
>> >        int tmp=i;
>> >        while(tmp!=0)
>> >        {
>> >           tmp=tmp&(tmp-1);
>> >           count++;
>> >        }
>> >    }
>> >   return count;
>> >
>> > }
>> >
>> > Worst Case complexity : O((b-a)*32)
>> >
>> > Please let me know if there is another gud way to do it.. :)
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> > On Tuesday, 24 July 2012 15:09:42 UTC+5:30, ruru wrote:
>> >
>> > > find no. of 1's in binary format of numbers from 1 to 100. like for
>> > > 1 to 10 answer is 17
>> >
>> > On Tuesday, 24 July 2012 15:09:42 UTC+5:30, ruru wrote:
>> >
>> > > find no. of 1's in binary format of numbers from 1 to 100. like for
>> > > 1 to 10 answer is 17
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to