My code is not getting submitted please give some hint

Problem Name --Playing with bits
Topic Bitmasking

#include<bits/stdc++.h>
using namespace std;
int main() {
long q,j,count=0,temp;
std::cin>>q;
while(q–){
long a,b,count=0;
cin>>a>>b;
for(j=a;j<=b;j++){

     temp = __builtin_popcount(j);
     count += temp;
   }
     cout<<count<<endl;
 }

return 0;
}

Dont use the inbuilt functions.
Use normal loop to extract bits.

i have tried without using inbuilt function as well still test case are not passing .It is showing TLE

Here is the code I submitted and it worked. Plain simple logic. __builtinpopcount() should also work ideally.

‘’'c
#include
using namespace std;

int countBits(int num)
{
int cnt = 0;

while(num)
{
	cnt += (num & 1);
	num >>= 1;
}
return cnt;

}

int main()
{
int testCases;
cin >> testCases;

while(testCases--)
{
    int a,b,total;
    
    cin >> a >> b;
    
    total = 0;
    
    for(int i = a ; i <= b ; i++)
    {
        total += countBits(i);
    }
    
    cout << total << "\n" ;
}

return 0;

}

‘’’