Java solution - 80ms
Intuition\n Describe your first thoughts on how to solve this problem. \nFor integers in ascending order, each power of 2 is present in a pattern. Let us consid
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nFor integers in ascending order, each power of 2 is present in a pattern. Let us consider the numbers up to 8 for reference and list their binary representations, up to 4 digits:\n\n0 --> 0000\n1 --> 0001\n2 --> 0010\n3 --> 0011\n4 --> 0100\n5 --> 0101\n6 --> 0110\n7 --> 0111\n8 --> 1000\n\nNow look at the pattern for each power of 2(column). Then each power of 2 has this pattern:\n1 --> $$01$$0101010\n2 --> $$0011$$00110\n4 --> $$00001111$$0\n\n1. We can use this to know the counts of each power of 2 in the *big_num* array before the representation starts for any given number x. \n\n2. Using 1, we can find the counts for each power of 2 in the desired index range.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Process each query individually.\n2. For each query [s, t, mod], binary search to find the numbers whose representation will contain the (s+1)th index and (t+1)th index, say m and n.\n3. Calculate the counts of each power of 2 less than m and less than n, to get the counts of each powers of 2 in the desired range.\n4. For a given ith power of 2 with count c, its contribution in the desired product will be $$2^{i*c}$$. Transfer over as much of the expoenent as you can to the next highest power of 2, by representing this exponent as: \n$$i*c =  (i+1) * \\lfloor((c*i)/(i+1))\\rfloor + ((c*i) mod (i+1)))$$\n\n    Now, the floor part of the previous formula is added to the count of the next power, while the remainder(which will be a lower power of 2 than i+1), is used in the product.\n5. For the highest power of 2, reduce the count until it is zero, by doubling the base of the exponent iteratively.\n\n\n\n# Complexity\n- Time complexity:\n\n    1. Binary search in the given range [1, n] will take $$O(log(n))$$ iterations.\n    2. For each number n, counting the sum of freq of powers of 2 will take $$O(log(n))$$ time.\n    3. Reducing the counts of each power of 2 to 0 will take a further $$O(log(n))$$ time.\n    \n    Hence for Q queries, the total time taken will be $$O(Q*(log^{2}(n))$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n    $$O(Q + log(n))$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public int[] findProductsOfElements(long[][] queries) {\n        \n        int[] response = new int[queries.length];\n        \n        for(int i=0; i<response.length; i++) {\n            response[i] = solve(queries[i][0], queries[i][1]+1, queries[i][2]);\n        }\n        \n        return response;\n    }\n    \n    public int solve(long s, long t, long mod) {\n        // Get the highest number x s.t. the sum of count of \n        // powers of 2 in integers in the range [0, x-1] is <= s\n        long n1 = s > 0 ? getNextHigher(1L, 100000_00000_00000L, s) : 0L;\n        // Get the sum of counts of each power for 2 in all \n        // integers less than x\n        long[] c1 = s > 0 ? getLowerCounts(n1) : new long[51];\n        // When the total count is less than target, use powers of \n        // 2 present in the binary rep. of x until total matches target\n        adjust(c1, n1, s);\n\n        // Do the same process for the higher target(t)\n        long n2 = getNextHigher(1L, 100000_00000_00000L, t);\n        long[] c2 = getLowerCounts(n2);\n        adjust(c2, n2, t);\n\n        // Calculate diff of counts to find counts of each \n        // powers in the desired range\n        for(int i=0; i<50; i++) {\n            c2[i] -= c1[i];\n        }\n        \n        // Calculate mod of each power of 2 for the current query\n        long[] pow = new long[50];\n        pow[0] = 1L;\n        for(int i=1; i<50; i++) {\n            pow[i] = pow[i-1] << 1;\n            pow[i] %= mod;\n        }\n        \n        // Calculate desired product here\n        long prod = 1L;\n        long next = 2L;\n        // Using the last element as sum of counts, no longer required\n        c2[50] = 0;\n\n        // For each power of 2, use the minimum count necessary \n        // to use, and roll over as much as possible into the next higher power\n        for(int i=1; i<50; i++) {\n            int rem = (int)((c2[i]*(i)) % (i+1));\n            long div = (c2[i]*i) / (i+1);\n            prod *= pow[rem];\n            prod %= mod;\n            \n            c2[i+1] += div;\n            next <<= 1;\n        }\n        \n        // For the highest power of 2, continually reduce the \n        // base of the exponent until the count is reduced to 0\n        long base = next % mod;\n        while(c2[50] > 0) {\n            prod *= (c2[50] % 2 == 1) ? base : 1L;\n            prod %= mod;\n            \n            base *= base;\n            base %= mod;\n            c2[50] >>= 1;\n        }\n        \n        return (int)(prod % mod);\n    }\n    \n    public void adjust(long[] c, long x, long target) {\n        int i=0;\n        // Start from the lowest bit, and increment until the \n        // total matches the target for each set bit\n        while(c[50] != target) {\n            if(x == 0) {\n                System.out.println("Error");\n                break;\n            }\n            if(x % 2 != 0) {\n                c[i]++;\n                c[50]++;\n            }\n            \n            x >>= 1;\n            i++;\n        }\n    }\n    \n    public long getNextHigher(long from, long to, long target) {\n        // Binary search for the highest number for which total \n        // count of powers of 2 for numbers <= target\n        if(from == to) {\n            return from;\n        }\n        long mid = from + (to+1-from)/2;\n        long[] counts = getLowerCounts(mid);\n        if(counts[50] > target) {\n            return getNextHigher(from, mid-1, target);\n        } else {\n            return getNextHigher(mid, to, target);\n        }\n    }\n    \n    public long[] getLowerCounts(long x) {\n        long[] response = new long[51];\n        long total = 0;\n        int i = 0;\n        long next = 1L;\n        // For a given power of 2(i), it is unset in the first 2^i nums, \n        // then set for the next 2^i nums and the pattern repeats.  \n        while(next < x) {\n            response[i] = (x/(2*next))*next + Math.max((x % (2*next))-next, 0);\n            total += response[i];\n            i++;\n            next <<= 1;\n        }\n        // Using the last element as a special num to represent total\n        response[50] = total;\n        return response;\n    }\n}\n```
['Java']