For a number X, let its "Coolness" be defined as the number of "101"s occurring in its…
- User
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 ≤ 10^5 1 ≤ K ≤ 100
SAMPLE INPUT 1 5 1
SAMPLE OUTPUT 1
Assistant
pythonimport bisect max_r = 10**5 coolness = [0] * (max_r + 1) # Precompute the coolness for each number up to max_r for i in range(1, max_r + 1): binary = bin(i)[2:] cnt = 0 for j in range(len(binary) - 2): if binary[j] == '1' and binary[j+1] == '0' and binary[j+2] == '1': cnt += 1 coolness[i] = cnt # Precompute lists for each K from 1 to 100 K_to_list = {} for K in range(1, 101): lst = [] for num in range(1, max_r + 1): if coolness[num] >= K: lst.append(num) K_to_list[K] = lst # Read input and process each test case T = int(input()) for _ in range(T): R, K = map(int, input().split()) if K > 100: print(0) else: lst = K_to_list[K] count = bisect.bisect_right(lst, R) print(count)
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.