Class Solution
-
- All Implemented Interfaces:
public final class Solution3145 - Find Products of Elements of Big Array\.
Hard
A powerful array for an integer
xis the shortest sorted array of powers of two that sum up tox. For example, the powerful array for 11 is[1, 2, 8].The array
big_numsis created by concatenating the powerful arrays for every positive integeriin ascending order: 1, 2, 3, and so forth. Thus,big_numsstarts as <code><ins>1</ins>, <ins>2</ins>, <ins>1, 2</ins>, <ins>4</ins>, <ins>1, 4</ins>, <ins>2, 4</ins>, <ins>1, 2, 4</ins>, <ins>8</ins>, ...</code>.You are given a 2D integer matrix
queries, where for <code>queriesi = from<sub>i</sub>, to<sub>i</sub>, mod<sub>i</sub></code> you should calculate <code>(big_numsfrom<sub>i</sub> * big_numsfrom<sub>i</sub> + 1 * ... * big_numsto<sub>i</sub>) % mod<sub>i</sub></code>.Return an integer array
answersuch thatanswer[i]is the answer to the <code>i<sup>th</sup></code> query.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 <= 500queries[i].length == 3<code>0 <= queries0<= queries1<= 10<sup>15</sup></code>
<code>1 <= queries2<= 10<sup>5</sup></code>
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final IntArrayfindProductsOfElements(Array<LongArray> queries)-
-
Method Detail
-
findProductsOfElements
final IntArray findProductsOfElements(Array<LongArray> queries)
-
-
-
-