You are not logged in. Please login at www.codechef.com to post your questions!

×

Need Help in a question

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/the-range-query/0

asked 11 Jul '18, 12:22

sagar_sam's gravatar image

4★sagar_sam
522
accept rate: 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 .

link

answered 11 Jul '18, 14:39

beginner_1111's gravatar image

4★beginner_1111
240110
accept rate: 13%

edited 11 Jul '18, 14:39

Thank you, got it. I should spend more time before asking.

(11 Jul '18, 15:03) sagar_sam4★
toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • 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