Multiple Ques in a single ques. || Binomial Modularity || Binary search || O(logn) || Math
\n# Complexity\n- Time complexity:\n Add your time complexity here, e.g. O(n) \nO(logn)\n- Space complexity:\n Add your space complexity here, e.g. O(n) \nO(n)\
\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n$$O(logn)$$\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n$$O(n)$$\n# Code\n```java []\nclass Solution {\n    \n    public int[] findProductsOfElements(long[][] queries) {\n        int n = queries.length;\n        int[] res = new int[n];\n        for (int i = 0; i < n; i++) {\n            long from = queries[i][0] + 1;\n            long to = queries[i][1] + 1;\n            long mod = queries[i][2];\n            \n            long lbb = lb(from);\n            long ubb = ub(to);\n            long[] a1 = make(lbb);\n            long[] a2 = make(ubb);\n            \n            increase(a1, from, lbb);\n            decrease(a2, to, ubb);\n            improve(a2, a1);\n            \n            long sum = set(a2);\n            res[i] = (int) me(sum, mod);\n        }\n        return res;\n    }\n\n    public static long me( long ex, long mod) {\n        long result = 1 , x = 1 , y = 2;\n        if(mod == 1) return 0;\n        while(x <= ex){\n            if( (ex & x) == x ){\n                result *= y;\n                result %= mod;\n            }\n            x <<= 1l;\n            y *= y;\n            y %= mod;\n        }\n        return result;\n    }\n\n    static long set(long[] a2) {\n        long sum = 0;\n        for (int i = 1; i < a2.length; i++) {\n            sum += (i * a2[i]);\n        }\n        return sum;\n    }\n\n    static void improve(long[] a2, long[] a1) {\n        int n = a2.length;\n        for (int i = 1; i < n; i++) {\n            a2[i] -= a1[i];\n        }\n    }\n\n    static void decrease(long[] ub, long to, long ubb) {\n        long x = bits(ubb) - to;\n        int i = ub.length - 1;\n        while (i >= 0 && x > 0) {\n            if (((ubb >> i) & 1) == 1) {\n                x--;\n                ub[i]--;\n            }\n            i--;\n        }\n    }\n\n    static void increase(long[] lb, long from, long lbb) {\n        long x = from - bits(lbb) - 1;\n        int i = 0,n = lb.length;\n        while (i < n && x > 0) {\n            if (((lbb + 1 >> i) & 1) == 1) {\n                x--;\n                lb[i]++;\n            }\n            i++;\n        }\n    }\n\n    static long[] make(long n) {\n        long[] arr = new long[47];\n        long x = 1 , kk = arr.length;\n        for (int i = 0; i < kk; i++) {\n            arr[i] = ((n / x) / 2) * x + ((n % x + 1) * ((n / x) % 2));\n            x *= 2;\n        }\n        return arr;\n    }\n\n    static long ub(long to) {\n        long s = 0, e = to, m, ans = -1;\n        while (s <= e) {\n            m = s + (e - s) / 2;\n            if (bits(m) >= to) {\n                ans = m;\n                e = m - 1;\n            } else {\n                s = m + 1;\n            }\n        }\n        return ans;\n    }\n\n    static long lb(long from) {\n        long s = 0, e = from, m, ans = -1;\n        while (s <= e) {\n            m = s + (e - s) / 2;\n            if (bits(m) < from) {\n                ans = m;\n                s = m + 1;\n            } else {\n                e = m - 1;\n            }\n        }\n        return ans;\n    }\n\n    static long bits(long n) {\n        long x = 1, s = 0;\n        for (int i = 0; i < 47; i++) {\n            s += ((n / x) / 2) * x + (n % x + 1) * ((n / x) % 2);\n            x *= 2;\n        }\n        return s;\n    }\n}\n\n```
['Array', 'Math', 'Binary Search', 'Bit Manipulation', 'Java']