Skip to content

Practice Range Product Queries of Powers

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#2438
LeetCode Problem

Range Product Queries of Powers

Problem Statement

Write positive n as the sum of the fewest powers of 2 and sort those powers in nondecreasing order to form powers. This array is unique. For each inclusive query [left,right], return the product of powers[left..right] modulo 10^9 + 7, in query order.

Source: Range Product Queries of Powers on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
n = 15, queries = [[0,1],[2,2],[0,3]]
Output
[2,4,64]

# Example 2

Input
n = 2, queries = [[0,0]]
Output
[2]

Constraints

1 <= n <= 10^9
1 <= queries.length <= 10^5
0 <= starti <= endi < powers.length

Related LeetCode Problems

Practice more problems similar to Range Product Queries of Powers.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.