Confusion in NUMGAME2

I used 2 representation for writing same condition:
1)if(n%4==1)

cout<<“ALICE”<<"\n";

else

cout<<“BOB”<<"\n";

link:http://www.codechef.com/viewsolution/3935830

2)if((n>>1)&1)

cout<<“BOB”<<"\n";

else

cout<<“ALICE”<<"\n";

link:http://www.codechef.com/viewsolution/3935851

I don’t know why second one gives WA ?
Both are running fine on my system…
reply asap…

Sometime in situations like this you can write a simple code to test what is going wrong :

    for i in range(10):
          print i,i%4==1, (i>>1)&1==False

O/P:

  0 False True  //fails
  1 True True
  2 False False
  3 False False
  4 False True  //fails
  5 True True
  6 False False
  7 False False
  8 False True  //fails
  9 True True

So your second code fails for the case when n%4==0.

2 Likes
//