Another optimised method possible?

Is there any other optimised method to solve this problem apart from the one mentioned below.

@Mudit809 there can be one

just precompute it in a dp array then answer will be dp(b) - dp(a-1) for every query. precompute is happening outside the query array and for counting set bits use builtin popcount function
i hope its clear if yes dont forget to mark it as resolved in my doubts section @Mudit809 :smiley:

@Mudit809 if your doubt is cleared please mark it as resolved