Easy Counting
Practice
3.3 (6 votes)
Combinatorics
Bit manipulation
Medium
Mathematics
Mathematics
Mathamatics
Problem
11% Success 1608 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Tubby the doggu wants you to solve a problem for him/her.

You have to find number of numbers between L to R inclusive whose binary representation of length P contains equal number of \(0's\) and \(1's\). It is guaranteed that \(P \ge ceil(log_2(R+1))\) . Here \(ceil(x)\) denotes the largest integer greater than or equal to x.

Example : Binary representation of number 5 of length 5 is \(00101\).

Input Format

The first line will consist of the integer T denoting the number of test cases.

For each of the T test cases, there will be single line containing 3 integers \(L,R\) \(and\) P.

Output Format

For each of the T test cases, output a single integer denoting the number of numbers between L to R inclusive whose binary representation of length P contains equal number of \(0's\) and \(1's\).

Constraints

\( 1 \le T \le 300000 \)

\( 1 \le L \le R \le 10^{16} \)

\( 1 \le P \le 60 \)

\( P \ge ceil(log2(R+1)) \)

WARNING: Large Input/output data, be careful with certain languages.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
4 votes
Tags:
MathematicsMediumOpenApprovedMathamatics
Points:30
4 votes
Tags:
C++MathSortingBasic Math
Points:30
Tags:
Data StructuresMathBasic MathArrays