
Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Find a way to calculate <code>f(n, i)</code> which is the total number of numbers in <code>[1, n]</code> when the <code>i<sup>th</sup></code> bit is set in <code>O(log(n))</code> time.
Use binary search to find the last number for each query (and there might be one “incomplete” number for the query).
Use a similar way to find the product (we only need to save the sum of exponents of power of <code>2</code>).