My issue
i am getting correct ans for
if((n%2==0) && ((n>>1)%2 ==0)) CodeChef: Practical coding for everyone
if(n%4==0) CodeChef: Practical coding for everyone
but not for
if((n&1==0) && ((n>>1)&1 ==0)) CodeChef: Practical coding for everyone
why as they are simply same condition
My code
#include <iostream>
#include<bits/stdc++.h>
#define ll long long int
#define mod 1000000007
using namespace std;
int main() {
cin.tie(0)->sync_with_stdio(false);
int t;cin>>t;
while(t--){
ll n;cin>>n;
int cnt=0;
if(n==1){
cout<<"Alice\n";
}
if(n==2){
cout<<"Bob\n";
}
if(n>2){
int cnt=0;
while(n){
if((n%2==0) && ((n>>1)%2 ==0)){
if(cnt%2)cout<<"Bob\n";
else cout<<"Alice\n";
break;
}
if(n==2){
if(cnt%2==0)cout<<"Bob\n";
else cout<<"Alice\n";
break;
}
if(n%2==1)n--;
else n>>=1;
cnt++;
}
}
}
cerr << "Time : " << 1000 * ((double)clock()) / CLOCKS_PER_SEC << "ms" << endl;
return 0;
}
Problem Link: Alice vs Bob Faceoff Practice Coding Problem