Here is another approach.
Example: 23 (00..10111)
1) Get count of all set bits at odd positions (For 23 it’s 3).
2) Get count of all set bits at even positions (For 23 it’s 1).
3) If difference of above two counts is a multiple of 3 then number is also
a multiple of 3.

(For 23 it’s 2 so 23 is not a multiple of 3)
Code for it:
http://codepad.org/eKI8ggs4



On Mon, Jun 7, 2010 at 1:12 AM, Raj N <rajn...@gmail.com> wrote:

> Dave's logic is working fine.
>
>
> On Mon, Jun 7, 2010 at 1:35 PM, Raj N <rajn...@gmail.com> wrote:
>
>> @Anand: The code you've sent is not correct. It doesn't work for numbers
>> 15,12 etc.
>>
>>
>> On Mon, Jun 7, 2010 at 2:20 AM, Minotauraus <anike...@gmail.com> wrote:
>>
>>> @Anand: Thanks for the code. I knew you could do it by bit
>>> shifting. :-)
>>>
>>> On Jun 5, 10:21 pm, Anand <anandut2...@gmail.com> wrote:
>>> > Here is a code for it.http://codepad.org/umkh3pjf
>>> >
>>> >
>>> >
>>> > On Sat, Jun 5, 2010 at 7:14 PM, Minotauraus <anike...@gmail.com>
>>> wrote:
>>> > > Subtract 3 from the number until either you get 0 or a negative
>>> > > number. If you get 0, its divisible, else not.
>>> > > You can probably do this by bit shifting too.
>>> >
>>> > > On Jun 5, 11:45 am, divya <sweetdivya....@gmail.com> wrote:
>>> > > > Find if a number is divisible my 3, without using %,/ or *. You can
>>> > > > use atoi().
>>> >
>>> > > --
>>> > > You received this message because you are subscribed to the Google
>>> Groups
>>> > > "Algorithm Geeks" group.
>>> > > To post to this group, send email to algoge...@googlegroups.com.
>>> > > To unsubscribe from this group, send email to
>>> > > algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com>
>>> <algogeeks%2bunsubscr...@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 algoge...@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@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 algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@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 algoge...@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