Very Cool Numbers
Practice
3.5 (159 votes)
Ad Hoc
Approved
Easy
Open
Problem
62% Success 15089 Attempts 20 Points 5s Time Limit 256MB Memory 1024 KB Max Code

For a number X, let its "Coolness" be defined as the number of "101"s occurring in its binary representation. For example, the number 21 has Coolness 2, since its binary representation is 101012, and the string "101" occurs twice in this representation.

A number is defined as Very Cool if its Coolness is greater than or equal to K. Please, output the number of Very Cool integers between 1 and R.

Input:
The first line contains an integer T, the number of test cases.
The next T lines contains two space-separated integers, R and K.
Output:
Output T lines, the answer for each test case.
Constraints:
1<=T<=100
1<=R<=105
1<=K<=100

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:20
13 votes
Tags:
Basic ProgrammingBasics of ImplementationEasyImplementation
Points:20
30 votes
Tags:
ApprovedCombinatoricsEasyMathOpenString Manipulation
Points:20
61 votes
Tags:
Ad-HocAlgorithmsApprovedBasic ProgrammingEasyOpen