c++() sieve
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```cpp []\nclass Solution {\npublic:\n  vector<long> n, f;  \n\n  vector<int> gcdValues(vector<int>& nums, vector<long long>& queries) {\n    int maxi = *max_element(nums.begin(), nums.end())+1;\n    vector<int> ans(queries.size());\n    n.resize(maxi);\n    f.resize(maxi);\n\n    for(int num: nums) n[num]++;\n    \n    for(int i = maxi-1; i; i--){\n      long tot = 0;\n      for (int j = i; j < maxi; j += i) tot += n[j];\n        \n      f[i] = (tot*(tot - 1))>>1;\n            \n      for (int j = i<<1; j < maxi ; j += i) f[i] -= f[j];\n    }\n\n    for(int i = 1; i != maxi; i++) f[i] += f[i-1];\n\n    for(int i = 0; i != queries.size(); i++)\n      ans[i] = binarySearch(queries[i]);\n\n    return ans;       \n  }\n\n  int binarySearch(long x){\n    int l = 0, r = f.size() - 1;\n\n    for(int m; l <= r;)\n      if(f[m = (l+r)>>1] <= x) l = m + 1;\n      else                     r = m - 1;\n\n    return l;\n  }\n};\n```
['C++']