Given Q queries, with each query consisting of two integers L and R, the task is to find the total numbers between L and R (Both inclusive), having atmost two set bits in their binary representation. Q<=10^5 L,R<=10^18 Question link: https://practice.geeksforgeeks.org/problems/therangequery/0 asked 11 Jul '18, 12:22

Hi, This can be solved using Precomputation(which will generate numbers with atmost 2 set bits in binary representation and then using binary search on the generated numbers. As the numbers are in the range of 10^18 , there can be atmost 60 bits in its binary representation. So use 2 loops (i,j) for simulating those values and then insert the generated number in a set (which maintains the sorting order) and then use binary search on the given ranges to find the answer which will surely fit within the time limit . answered 11 Jul '18, 14:39
