Trains the technique from
LeetCode 2438Range Product Queries of PowersThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
The number n can be written as a sum of powers of two, each used at most once, and in exactly one way. List those powers in increasing order and call the list pieces.
Each entry of queries is a pair [from, to] naming a stretch of pieces, both ends included. Answer each with the product of the pieces in that stretch, taken modulo 10^9 + 7.
Return the answers in the order the queries are asked.
Example 1
Seven splits into 1, 2 and 4, and the whole stretch multiplies to 8.
Example 2
Twelve splits into 4 and 8, and each query asks for one of them on its own.
Example 3
The eight pieces are the powers of two from 1 up to 128, so their exponents add to 28 and the product is two to that.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def product_queries(n: int, queries: list[list[int]]) -> list[int]:public int[] productQueries(int n, int[][] queries)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.