c++ solution
\nclass Solution {\npublic:\n    vector<int>getFactor(int n){\n        vector<int>nums;\n        for(int i=1;i*i<=n;i++){\n            if(n%i==0){\n            
```\nclass Solution {\npublic:\n    vector<int>getFactor(int n){\n        vector<int>nums;\n        for(int i=1;i*i<=n;i++){\n            if(n%i==0){\n                nums.push_back(i);\n                if(n/i!=i) nums.push_back(n/i);\n            }\n        }\n        return nums;\n    }\n    vector<int> gcdValues(vector<int>& nums, vector<long long>& queries) {\n        int maxElement=*max_element(nums.begin(),nums.end());\n        long long gcd[maxElement+1];\n        memset(gcd,0,sizeof(gcd));\n        for(auto &num:nums){\n            for(auto &f:getFactor(num)){\n                gcd[f]++;\n            }\n        }\n        \n        for(int i=maxElement;i>=1;i--){\n            gcd[i]=gcd[i]*(gcd[i]-1)/2;\n            for(int j=2*i;j<=maxElement;j+=i){\n                gcd[i]-=gcd[j];\n            }\n        }\n        \n        for(int i=1;i<=maxElement;i++){\n            gcd[i]+=gcd[i-1];\n        }\n        vector<int>ans;\n        for(auto &query:queries){\n            auto index = lower_bound(gcd,gcd+maxElement,query+1)-gcd;\n            ans.push_back(index);\n        }\n        return ans;\n    }\n};\n```
['C', 'C++']