Doubt in implementation of the code

Hello, I am facing the problem in my implementation. It is giving me TLE (time limit exceeded). How can I resolve the issue ?

Hello @yashsharma4304 i have corrected your code:


if you have any doubt you can ask here:
Happy Learning!!

Ok so you have made another variable k so that no. won’t change. But why we use while loop ?

So first loop was for taking q queries
Second loop was for iterating over numbers between a to b
And third loop was for iterating over the bits of a number k (a<= k <= b)

Right ?

@yashsharma4304 yes you are right.
while loop until the number becomes 0.

Ok is there any other optimized implementations ?
Because the time complexity is high in this approach

@yashsharma4304 yes you can use __builtin_popcount as well.


see this:
Happy Learning!!

1 Like

Thank you for clearing my doubts.

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.