"playing with bits" shows TLE

#include
using namespace std;
int main() {

int q; cin>>q;
for(int p=1;p<=q;p++)
{
    int a,b; cin>>a>>b;
    int count =0;
    for(int i=a;i<=b;i++)
    {   int k=i;
        while(k)
        {
            if(k & 1)
            count++;
            
            k>>1;
            
        }
        
    }
    
    cout<<count<<endl;
    
    
    
    
}



return 0;

}

Try Brian Kernighan’s Algorithm :
Subtraction of 1 from a number toggles all the bits (from right to left) till the rightmost set bit(including the righmost set bit). So if we subtract a number by 1 and do bitwise & with itself (n & (n-1)), we unset the righmost set bit. If we do n & (n-1) in a loop and count the no of times loop executes we get the set bit count.

So just do :

count = 0
while (n)
{
  n &= (n-1) ;
  count++;
}

can’t understand the input

You need to count the number of set bits in all the number in the range a to b, both inclusive.
Say, a=3 and b=6, you need to find the number of 1s in the binary representation of all the numbers from 3 to 6. So, 11 , 100 , 101 , 110 has a total of 2+1+2+2 = 7 set bits.