Is there any other optimised method to solve this problem apart from the one mentioned below.
Another optimised method possible?
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 