enter code here
#include
using namespace std;
int countDigits(long long a){
int count=0;
while(a){
a=(a&(a-1));
count++;
}
return count;
}
int main(){
ios_base::sync_with_stdio(false);
int T;
cin>>T;
while(T--){
long long A,B;
cin>>A>>B;
int ans;
if(B==0){
ans=-1;
}
else if(B==1 ){
if(A==0)
ans=1;
else{
ans=-1;
}
}
else if(A==B){
ans=0;
}
else{
int digitsA=countDigits(A);
int digitsB=countDigits(B-1);
//cout<<"Digit A:"<<digitsA;
//cout<<"Digit b:"<<digitsB;
//cout<<endl;
if(digitsB<digitsA)
ans=2;
else
ans=digitsB-digitsA+1;
}
cout<<ans<<'\n';
}
}
Please look into solution.
I am getting WA.
Unable to resolve error