Playing with bits

I have written a code and it is working fine with all my inputs but still giving a wrong ans . Please look at my code and tell what is the error.

Please provide your code on Coding Blocks IDE and also add some comments.

#include
#include<bits/stdc++.h>
using namespace std;

int main() {

int q,a[100],b[100];
cin >> q;
int j=0;
cout<<endl;
for(int i=0;i < q;i++){
    cin >> a[j]>>b[j];
    cout<<endl;
	j++;

}

for(int k=0; k <2;k++){
int no = 0;
for(int j=a[k]; j <= b[k]; j++){
    no = no +__builtin_popcount(j);
}
cout<<no<<endl;
}

}

You have taken the input wrong. you can directly cin >> a[i] >> b[i]. I am unable to understand why have you used j to take input. and also you have added two extra cout << endl; statements. They can be the reason for WA.

Also the loop for k must be till q. As you have to answer q queries and not 2.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.