Iterated Bitcount Function
CodeChefOpen on judge ↗
Let f(x) be the number of 1's in the binary representation of x. We can define f^k(x) as f(x) for k = 1, and f^(k-1)(f(x)) for k > 1. Let f^*(x) be the smallest k >= 1 such that f^k(x)=1. Given N and K, how many numbers x between 1 and N inclusive have f^*(x) = K ? Input The first line contains the number of test cases T. Each of the next T lines contains two space separated numbers N and K. O
HINT LADDERno hints yet
L1 Observation
L2 Technique
L3 Approach
L4 Pseudo-code
🔒
L5 Full solution
L5 unlocks only if you insist twice
solution.cppC++17
CodeSearch Tutor
Hints, not spoilers — it won’t hand over the full solution unless you insist.
Sign in to chat with the tutor and save your progress.
Sign in to start