Inclusion - Exclusion Principle || Beats 100% || Binary Search || Prefix Sum || CPP
Complexity\n- Time complexity:O(nlogn)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity:O(max(nums))\n Add your space complexity here, e.g. O(n
# Complexity\n- Time complexity:$$O(nlogn)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:$$O(max(nums))$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    vector<int> gcdValues(vector<int>& nums, vector<long long>& queries) {\n        int n = nums.size();\n        int mx = *max_element(nums.begin(), nums.end());\n        vector<int> mp(mx+1);\n        for(auto &it: nums) mp[it]++;\n        vector<long long> gcdValue(mx+1);\n        for(int i=mx; i>=1; i--){\n            int c1 = 0;\n            long long sub = 0;\n            for(int j=i; j<=mx; j+=i){\n                c1 += mp[j];\n                sub += gcdValue[j];\n            }\n            gcdValue[i] = 1LL * c1 * (c1 - 1) / 2 - sub;\n        }\n        for(int i=1; i<=mx; i++) gcdValue[i] += gcdValue[i-1];\n        vector<int> ans;\n        for(auto &q: queries){\n            int lo = 1, hi = mx;\n            int val = -1;\n            while(lo <= hi){\n                int mid = lo + (hi - lo) / 2;\n                if(gcdValue[mid] >= (q+1)){\n                    val = mid;\n                    hi = mid - 1;\n                }else lo = mid + 1;\n            }\n            ans.push_back(val);\n        }\n        return ans;\n    }\n};\n```
['C++']