Playing with Bits

can someone tell the approach to this problem

hi @akshat42bajpai
u can simply perform a brute force method… refer this code -->

#include<iostream>
using namespace std;
int main(){
	
	int t;
	cin>>t;
	for(int i=0;i<t;i++){
        int a,b;
        cin>>a>>b;
        
        int count = 0;
        for(int j=a;j<=b;j++){
            int num = j;
                
            while(num>0){
                int rem = num%2;
                if(rem == 1){
                    count++;
                }
                num=num/2;
            }
        }
        cout<<count<<endl;
	}
}

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.