The code is showing tle

#include
using namespace std;
int main() {
int q;
cin>>q;
while(q–)
{
int a,b;
cin>>a>>b;
int cnt=0;
for(int i=a;i<=b;i++)
{
while(i>0)
{
int last=(i&1);
if(last==1)
{
cnt++;
}
i=i>>1;
}
}
cout<<cnt<<endl;
}
return 0;
}

Hey, you need to optimise your count set bit function.There is a O(set bit ) available ,use that method.
Hint:search Brian Kernighan algorithm online