Range Queries

4.5

2 votes
Bit Manipulation, Basics of Bit Manipulation, Basic Programming
Problem

Given  queries of type , find the count of integers in range  such that their  bit (1-indexed) is from the LSB (least significant bit) side.

Input Format:

  • First line contains an integer , denoting the number of queries.
  • Next  lines contains three space-separated integres .

Output Format:

For every query, print the number of integers in  which satisfy the above condition.

Constraints:

Sample Input
1
2 6 2
Sample Output
3
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation
  • Binary representation of integers in range  are as follows:-
    • 2 : 10
    • 3 : 11
    • 4 : 100
    • 5 : 101
    • 6 : 110
  • There are three integers with X-th bit ON i.e. 2, 3 and 6.
  • Thus, required answer is 3.
Editor Image

?