GAMENUM WA

I was solving GAMENUM problem from the Campus Chapters Contest 1.0 (CodeChef: Practical coding for everyone) .

#include<bits/stdc++.h>

using namespace std;

#define FAST_IO(value) ios :: sync_with_stdio(value); std :: cin.tie(value)
#define ll long long
ll numofbits(ll x){
return log2l(x);
}

int main(){
FAST_IO(0);
int t;
cin>>t;
while(t–){
ll a,b; int opcount=0;
cin>>a>>b;

    ll left_shift= numofbits(max(a,b));
   
    ll updated_b= b;
    ll max_xor= a ^ b;
   
    while(true){
        ll bmod= updated_b & 1;
        updated_b =(updated_b>>1 | bmod<< left_shift);
        if(updated_b == b){
           break;
        }
        if(max_xor < (a ^ updated_b))
           {
               max_xor = a ^ updated_b;
               opcount++;
           }
        
    }
    cout<<opcount<<" "<<max_xor;
    cout<<'\n';
}
return 0;

}

This is my solution, the sample test case passes successfully but the rest is evaluated as WA. Can someone kindly help?

Use the fact that, Right-Rotate By One has a cyclic/periodic nature i.e. when you right-rotate any number by 1 you will get the same number after n rotations where n = number of bits required to represent the number.

Firstly use this for bitcount

ll numofbits(ll x){
    return 64 - __builtin_clzll(x);
}

Secondly, why is opcount++ in the if condition?

You need one variable to store the number of operations, and one variable to store the number of operations done when you found the maximum value.

https://www.codechef.com/viewsolution/32006143

Thank you, I corrected it.

Okay, thank you :slight_smile: