Playing with bits

there is some timelimit in my code ,
plz help me

You are applying the brute force for solving the answer which is not optimal solution:

solution approach: lets range is (a,b) first find out the number of set bits in the integers in range y = (0,b) then find out the number of set bits in the integers in range x = (0,a-1) and then calculate the answer as y-x.

Finding out the no of set bits in range(0,b) - see in c++ the integers is 32 bits long. common observation is this is that the lsb bit is set and reset in every consecutive number. 2nd lsb bit flips after two consecutive numbers and remains for two consecutive numbers.
eg. 00, 01,10,11,100, here lsb is different in every consecutive number and 2nd lsb bit is fliping after every two numbers and remains same for two numbers as well.

try to solve the question using this approach and feel free to ask if you still have any doubt.

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.