Easy to understand || Beats 100% || Bit Manipulation + Binary Search || C++
Complexity\n- Time complexity:O(q.log^2n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity:O(logn)\n Add your space complexity here, e.g. O(n) 
# Complexity\n- Time complexity:$$O(q.log^2n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:$$O(logn)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    using ll = long long;\n    // binary exponentiation for computing the power of the number\n    ll binpow(ll a, ll b, ll m) {\n        a %= m;\n        ll res = 1;\n        while (b > 0) {\n            if (b & 1)\n                res = res * a % m;\n            a = a * a % m;\n            b >>= 1;\n        }\n        return res;\n    }\n    // function to find the setBitsCount at the bit position for the numbers from 0...n\n    vector<ll> setBitsCount(ll num){\n        vector<ll> cnt(61);\n        for(ll i=60; i>=0; i--){\n            ll d = 1LL << i;\n            ll q = num / d;\n            if(q & 1){\n                cnt[i] += num - d * q;\n            }\n            cnt[i] += q/2 * d;\n        }\n        return cnt;\n    }\n    // function to find the total count of the set bits for the numbers from 0...n\n    ll totalBits(ll num){\n        vector<ll> cnt = setBitsCount(num + 1);\n        ll sum = 0;\n        for(ll i=0; i<61; i++) sum += cnt[i];\n        return sum;\n    }\n    // function to find the number which is at the query index\n    ll findLimit(ll num){\n        ll s = 1, e = 1e15;\n        ll ans = 1e15;\n        while(s <= e){\n            ll mid = s + (e - s) / 2;\n            if(totalBits(mid) >= num){\n                ans = mid;\n                e = mid - 1;\n            }else s = mid + 1;\n        }\n        return ans;\n    }\n    vector<int> findProductsOfElements(vector<vector<long long>>& queries) {\n        /* \n        Steps to solve this problem:\n        1. First find the lower and upper limit of the range using binary search.\n        2. Find the bit frequency within the range of the limits\n        3. Just do binary exponentiation and find out the result\n        */\n        vector<int> ans;\n        for(auto it: queries){\n            ll cl = it[0], ch = it[1] + 1, mod = it[2];\n            ll l = findLimit(cl) - 1;\n            ll h = findLimit(ch);\n            vector<ll> cntL = setBitsCount(l + 1);\n            vector<ll> cntH = setBitsCount(h + 1);\n            ll sumH = totalBits(h);\n            ll sumL = totalBits(l);\n            // handling the excess case, when the total set bit count is greater than the required.\n            for(ll i=60; i>=0; i--){\n                if((h >> i) & 1){\n                    if(ch < sumH){\n                        sumH--;\n                        cntH[i]--;\n                    }\n                }\n            }\n            l += 1;\n            // handling the limit, when the total set bit count is lesser than the required.\n            for(ll i=0; i<61; i++){\n                if((l >> i) & 1){\n                    if(cl > sumL){\n                        sumL++;\n                        cntL[i]++;\n                    }\n                }\n            }\n            // now finding the set bit count of each bit position for the numbers within the range\n            for(ll i=0; i<61; i++) cntH[i] -= cntL[i];\n            ll pd = 1;\n            // now computing the required result\n            for(ll i=0; i<61; i++){\n                pd = (pd * binpow(1LL << i, cntH[i], mod)) % mod;\n            }\n            ans.push_back(pd);\n        }\n        return ans;\n    }\n};\n```
['C++']