Class Solution

  • All Implemented Interfaces:

    
    public final class Solution
    
                        

    3145 - Find Products of Elements of Big Array.

    Hard

    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 <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 answer such that answer[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 &lt;= queries.length &lt;= 500

    • queries[i].length == 3

    • <code>0 <= queries0<= queries1<= 10<sup>15</sup></code>

    • <code>1 <= queries2<= 10<sup>5</sup></code>

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
      Solution()
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final IntArray findProductsOfElements(Array<LongArray> queries)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait