#include
using namespace std;
int countBits(int n)
{
int ans=0;
while(n>0)
{
ans=ans+(n&1);
n=n>>1;
}
return ans;
}
int main() {
int q,res=0;
cin>>q;
while(q--)
{
int a,b,i;
cin>>a>>b;
for(i=a;i<=b;i++)
{
res=res+countBits(i);
}
cout<<res<<endl;
}
return 0;
}
For the test case 10,15 the output is coming as 18 instead of 17. I dry ran the code, but couldn’t find out the mistake.