Binary Search + concept of set bits
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n#define ll long long int\nll setBits(ll n,ll x){\n   return (n/(1LL<<(x+1)))*(1LL<<x)+max(0LL,(n%(1LL<<(x+1)))-(1LL<<x)+1);\n}\nll setBits(ll n){\n    ll ans=0;\n    for(ll i=0;i<60;i++) ans+=setBits(n,i);\n    return ans;\n}\n\nclass Solution {\n    ll mod;\n    ll poww(ll a,ll b){\n    if(a==1 or a==0 or b==1) return a%mod;\n    if(b==0) return 1;\n    ll ans=poww(a,b/2);\n    ans=(ans%mod*ans%mod)%mod;\n    if(b%2) ans=(ans%mod*a%mod)%mod;\n    return ans;\n    }\n\n    ll find_ele(ll v){\n        ll low=1,high=1e15;\n        ll ans;\n        while(low<=high){\n            ll mid=(low+high)/2;\n            if(setBits(mid)>=v) ans=mid,high=mid-1;\n            else low=mid+1;\n        }\n        return ans;\n    }\n    ll solve(ll a,ll b){\n        ll f=find_ele(a),s=find_ele(b); \n        if(f==s){\n            ll st=a-setBits(f-1); \n            ll e=b-setBits(s-1); \n            vector<ll>sb; \n            for(ll i=0;i<60;i++){\n            if(f & (1LL<<i)) sb.push_back(i);\n             }\n            ll ans=1;\n            for(ll i=st-1;i<e;i++) ans*=(1LL<<sb[i]);\n            return ans%mod;\n        }\n        vector<ll>temp(60,0);\n        for(ll i=0;i<60;i++){\n            if(s-1>f) temp[i]=setBits(s-1,i)-setBits(f,i);\n        } \n        ll st=a-setBits(f-1); \n        vector<ll>sb; \n        for(ll i=0;i<60;i++){\n            if(f & (1LL<<i)) sb.push_back(i);\n        }\n        for(ll i=st-1;i<sb.size();i++) temp[sb[i]]++;\n        sb.clear(); \n        ll e=b-setBits(s-1); \n        for(ll i=0;i<60;i++){\n            if(s & (1LL<<i)) sb.push_back(i);\n        }\n        for(int i=0;i<e;i++) temp[sb[i]]++; \n        ll ans=1; \n        for(ll i=0;i<60;i++){\n            if(temp[i]){\n                ans=(ans * poww(1LL<<i,temp[i]))%mod;\n            }\n        }\n        return ans%mod;\n    }\npublic:\n    vector<int> findProductsOfElements(vector<vector<long long>>& queries) {\n        vector<int>ans;\n        for(auto q:queries){\n            mod=q[2];\n            ans.push_back(solve(q[0]+1,q[1]+1));\n        }\n        return ans;\n    }\n};\n```
['C++']