Dont came to understand the question properly

Prateek Bhayia likes to play with bits. One day Prateek bhayia decides to assign a task to his student Sanya. You have help Sanya to complete this task. Task is as follows - Prateek Bhayia gives Q queries each query containing two integers a and b. Your task is to count the no of set-bits in for all numbers between a and b (both inclusive)

@soorya19k the question is simple you are two integers a and b you have count set bits for each number between a and b and output their sum.

1 Like

i have written a code but i am not getting correct output.
#include<bits/stdc++.h>
using namespace std;

int count(int &n){
int ans=0;
while(n>0){
n=n&(n-1);
ans++;
}
return ans;
}
int main() {
int q;cin>>q;
while(q–){
int res=0;
int a,b;cin>>a>>b;
for(int i=a;i<=b;i++){
res+=count(i);
}
cout<<res;
}
return 0;
}