awesome solution

On Tue, May 3, 2011 at 1:43 PM, anshu <[email protected]> wrote:

> algorithm:
>
> if any number(a) is divisible by 5 it can be wriiten as 4*b + b -->
> this cleary shows the last two bit of a & b will be same.
>
> lets understand by an example (35)10 = (100011)2
>
>  xx1100
> +   xx11
> ---------
>  100011
>
> now this clearly shows we can calculate the unknowns(x) by traversing
> right to left
>
> code:
>
> int main()
> {
>        int n, m;
>        cin >> n;
>        m = n;
>
>        int a, b;
>        int i=2;
>
>        a = (m&3)<<2;
>        b = (m&3);
>        m >>= 2;
>
>        bool rem = 0,s,r;
>
>        while (m>3)
>        {
>                r = a&(1<<i);
>                s = r^(m&1)^rem;
>                b = b|(s<<i);
>                a = a|(s<<(i+2));
>                rem = (r&s)|(s&rem)|(r&rem) ;
>                i++;
>                m >>= 1;
>        }
>
>        if (a+b == n) cout << "yes\n";
>        else cout << "no\n";
>
>        return 0;
> }
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>


-- 
Regards
Aditya Kumar
B-tech 3rd year
Computer Science & Engg.
MNNIT, Allahabad.

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

Reply via email to