##### Welcome to Subscribe On Youtube

# 3145. Find Products of Elements of Big Array

## Description

A **powerful array** for an integer `x`

is the shortest sorted array of powers of two that sum up to `x`

. For example, the powerful array for 11 is `[1, 2, 8]`

.

The array `big_nums`

is created by concatenating the **powerful** arrays for every positive integer `i`

in ascending order: 1, 2, 3, and so forth. Thus, `big_nums`

starts as `[`

.__1__, __2__, __1, 2__, __4__, __1, 4__, __2, 4__, __1, 2, 4__, __8__, ...]

You are given a 2D integer matrix `queries`

, where for `queries[i] = [from`

you should calculate _{i}, to_{i}, mod_{i}]`(big_nums[from`

._{i}] * big_nums[from_{i} + 1] * ... * big_nums[to_{i}]) % mod_{i}

Return an integer array `answer`

such that `answer[i]`

is the answer to the `i`

query.^{th}

**Example 1:**

**Input:** queries = [[1,3,7]]

**Output:** [4]

**Explanation:**

There is one query.

`big_nums[1..3] = [2,1,2]`

. The product of them is 4. The remainder of 4 under 7 is 4.

**Example 2:**

**Input:** queries = [[2,5,3],[7,7,4]]

**Output:** [2,2]

**Explanation:**

There are two queries.

First query: `big_nums[2..5] = [1,2,4,1]`

. The product of them is 8. The remainder of 8 under 3 is 2.

Second query: `big_nums[7] = 2`

. The remainder of 2 under 4 is 2.

**Constraints:**

`1 <= queries.length <= 500`

`queries[i].length == 3`

`0 <= queries[i][0] <= queries[i][1] <= 10`

^{15}`1 <= queries[i][2] <= 10`

^{5}