Bit manipulation, beats 100% at the time of writing
Intuition\n\nEach number in the big_nums is a power of two. Since the answer is the product modulo some given number it is more convenient to work with exponent
# Intuition\n\nEach number in the `big_nums` is a power of two. Since the answer is the product modulo some given number it is more convenient to work with exponents, that is with the non-zero bit positions.\n\nThe naive solution is the following:\n```python\ndef bit_pos():\n    n = 0\n    while True:\n        n0 = n\n        while n0 > 0:\n            bit = n0 & (-n0)\n            n0 ^= bit\n            yield bit.bit_length()-1\n        n += 1\n\n\ndef naive(lo, hi, modulo):\n    return pow(2, sum(itertools.islice(bit_pos(), lo, hi+1)), modulo)\n```\n\nWhat it does is the following: `bit_pos` is an infinite generator that produces the sequences of exponents (`bit.bit_length()-1`). Then the function `naive` accumulates the exponents in the given range and takes the power of two mod `modulo`.\n\nThe optimized version first computes $k$ such that the first $n$ element of the `big_nums` are coming from the integers `1,...,k` and not all bits of $k$ are used.\nUsing $k$ it is easy to find the sum of exponents of the first $n$ elements in `big_nums`.\n\n\n# Code\n```\ndef efficient(lo, hi, modulo):\n    return pow(2, bigarray_prefixsum(hi+1)-bigarray_prefixsum(lo), modulo)\n\n\ndef bitcount_inv(n):\n    """Returns k such that \n    bit_count(k) <= n < bit_count(k) + k.bit_count()    \n    """\n    lo = 0\n    hi = 1 << 46\n    while lo < hi:\n        med = (lo+hi+1)//2\n        if bit_count(med) <= n:\n            lo = med\n        else:\n            hi = med-1\n    return lo\n\ndef bigarray_prefixsum(n):\n    """Computes\n    sum(itertools.islice(bit_pos(), n))\n    efficiently\n    """\n    k = bitcount_inv(n)\n    total = bitpos_sum(k)\n    n0 = n-bit_count(k)\n    while n0 > 0:\n        bit = k & (-k)\n        n0 -= 1\n        k ^= bit\n        total += bit.bit_length()-1\n    return total\n\ndef bit_count(n):\n    """\n    computes:\n    ```\n    def count(n):\n        total = 0\n        for k in range(n):\n            total += k.bit_count()\n        return total\n    ```    \n    efficiently\n    """\n    total = 0\n    total_bits = n.bit_count()\n    while n > 0:\n        bit = n & (-n)\n        n -= bit\n        bit_pos = bit.bit_length()-1\n        total_bits -= 1\n        total += total_bits << bit_pos\n        if bit_pos > 0:\n            total += bit_pos << (bit_pos-1)\n    return total\n\n\ndef bitpos_sum(n):\n    """Computes:\n    ```\n    def count(n):\n        total = 0\n        for k in range(n):\n            while k > 0:\n                bit = k & (-k)\n                k ^= bit\n                total += bit.bit_length()-1\n        return total\n    ```\n    efficiently\n    """\n    n0 = n\n    bit_pos_sum = 0\n    while n0 > 0:\n        bit = n0 & (-n0)\n        n0 ^= bit\n        bit_pos_sum += bit.bit_length()-1\n        \n    total = 0\n    while n > 0:\n        bit = n & (-n)\n        n ^= bit\n        bit_pos = bit.bit_length()-1\n        bit_pos_sum -= bit_pos\n        total += (bit_pos_sum << bit_pos) \n        if bit_pos > 1:        \n            total += (bit_pos*(bit_pos-1)) << (bit_pos-2) \n    return total\n\nclass Solution:\n    def findProductsOfElements(self, queries: List[List[int]]) -> List[int]:\n        return [efficient(lo, hi, modulo) for lo, hi, modulo in queries]\n```
['Python3']