Binary Search Solution | C++ | 200ms
Binary search solution\n# Code\n\nclass Solution {\npublic:\n    long long countOnes(long long x, long long cycle, long long pow2Is) {\n        if (x < 0) {\n  
Binary search solution\n# Code\n```\nclass Solution {\npublic:\n    long long countOnes(long long x, long long cycle, long long pow2Is) {\n        if (x < 0) {\n            return 0;\n        }\n        long long totCycle = x / cycle;\n        long long ones = (totCycle * pow2Is);\n        long long left = x % cycle;\n        left++;\n        left -= pow2Is;\n        return ones + max(0ll, left);\n    }\n\n    long long power(long long a, long long b, long long mod) {\n        long long ans = 1;\n        a = a % mod;\n        while (b) {\n            if (b % 2) {\n                ans = (ans * a) % mod;\n            }\n            b = b / 2;\n\n            a = (a * a) % mod;\n        }\n        return ans;\n    }\n\n    vector<long long> computeVec(long long x) {\n        long long s = 0, e = 1000000000000000ll, numOfOnes = 0, num = 0;\n        vector<long long> freq(61, 0);\n        while (s <= e) {\n            long long mid = (s + e) / 2;\n            long long ones = 0;\n            vector<long long> f(61, 0);\n            for (int j = 0; j <= 60; j++) {\n                long long pow2Is = (1ll << j);\n                long long cycle = (1ll << (j + 1));\n                long long o = countOnes(mid, cycle, pow2Is);\n                ones += o;\n                f[j] = o;\n            }\n            if (ones <= x) {\n                numOfOnes = ones;\n                num = mid;\n                for (int i = 0; i <= 55; i++) {\n                    freq[i] = f[i];\n                }\n                s = mid + 1;\n            } else {\n                e = mid - 1;\n            }\n        }\n        if (numOfOnes < x) {\n            long long left = x - numOfOnes;\n            long long number = num + 1;\n            long long int index = 0;\n            while (left and index < 60) {\n                if (number & (1ll << index)) {\n                    left--;\n                    freq[index]++;\n                }\n                index++;\n            }\n        }\n\n        return freq;\n    }\n\n    long long compute(long long x, long long y, long long mod) {\n        x = max(0ll, x);\n        vector<long long> f1 = computeVec(y);\n        vector<long long> freq = computeVec(x);\n        long long ans = 1;\n        for (int j = 0; j <= 55; j++) {\n            long long pow2Is = (1ll << j);\n            long long cycle = (1ll << (j + 1));\n            long long o = f1[j] - freq[j];\n            ans = (ans * power(pow2Is, o, mod)) % mod;\n        }\n        return ans;\n    }\n    vector<int> findProductsOfElements(vector<vector<long long>>& queries) {\n        vector<int> ans;\n        for (auto i : queries) {\n            long long x = i[0];\n            long long y = i[1];\n            long long mod = i[2];\n            long long add = compute(x, y + 1, mod) % mod;\n            ans.push_back(add);\n        }\n        return ans;\n    }\n};\n```
['Binary Search', 'C++']