Runguard: warning: time limit exceeded (wall time): aborting command error

The following error is shown when I try to run the code.


THE CODE is as follow:
image of the code:

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

whereas
this following code runs fine:
#include
using namespace std;
int countSetBits(int i){
int count=0;
while(i>0){
if(i&1)
count++;
i=i>>1;
}
return count;
}
int main() {
int q;
cin>>q;
while(q–){
int a,b;
cin>>a>>b;
int count =0;
for(int i=a;i<=b;i++){
count+= countSetBits(i);
}
cout<<count<<endl;
}
return 0;
}

hi @mohitgodara2352002
i can see that u have successfully submitted the code and gained full points… is there still anything??

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.