Playing with bits

it shows tle
#include
using namespace std;

int main() {
int q;
cin>>q;
while(q–){
int a,b;
cin>>a>>b;
int res=0;
for(int i=a;i<=b;i++){
int cnt =0;
while(i>0){
if((i&1)==1){
cnt++;
}
i>>1;
}
res+=cnt;

   }
   cout<<res<<endl;

}
return 0;

}

Hi @kumarakash121005
U are doing mistake in while loop and value of i is not changing, hence it give TLE as loop goes on indefinitely…
correction -->
i = i>>1
Write like this… ur code should work fine…

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.