×

# Need Help in a question

 0 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 asked 11 Jul '18, 12:22 52●2 accept rate: 0%

 0 Hi, This can be solved using Pre-computation(which will generate numbers with at-most 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 at-most 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 240●1●10 accept rate: 13% Thank you, got it. I should spend more time before asking. (11 Jul '18, 15:03)
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×77

question asked: 11 Jul '18, 12:22

question was seen: 97 times

last updated: 11 Jul '18, 15:03