Problem · Bit Manipulation
Get Query Results
Learn this problemProblem statement
For a positive integer N, its goodArray is the smallest multiset of powers of two whose sum is N. Equivalently, it contains one power of two for every set bit in the binary representation of N. Sort this array in non-decreasing order.
Each query is [l, r, m] and uses 1-based inclusive positions. Compute the product of goodArray[l] through goodArray[r], modulo m.
Return the answers in query order.
Function
getQueryResults(N: long, queries: int[][]) → int[]Examples
Example 1
N = 26queries = [[1, 2, 1009], [3, 3, 5]]return = [16, 1]The sorted good array is [2, 8, 16].
- For
[1, 2, 1009], the answer is(2 × 8) mod 1009 = 16. - For
[3, 3, 5], the answer is16 mod 5 = 1.
Constraints
1 ≤ N ≤ 10^181 ≤ queries.length ≤ 10^5- Each query contains exactly three integers
[l, r, m]. 1 ≤ l ≤ r ≤ goodArray.length1 ≤ m ≤ 10^5
More IBM problems
- Parent Process NumberOA · Seen Jul 2026
- Request Retry CountOA · Seen Jul 2026
- Count Strictly Increasing Subsequences of Length 3OA · Seen Jul 2026
- Maximum Requests in a Time WindowOA · Seen Jul 2026
- Query Type Frequency WindowOA · Seen Jul 2026
- Minimum Number of Non-Empty Disjoint SegmentsOA · Seen Jul 2026
- Spam Text ClassificationOA · Seen Jul 2026
- Count Ideal NumbersOA · Seen Jun 2026