[C++] Short solution
calculate for each i from 1 to maxiumum element how many array elements are divible by i.\n- use the divisors array calculated before to calculate for each i ho
- calculate for each i from 1 to maxiumum element how many array elements are divible by i.\n- use the divisors array calculated before to calculate for each i how many pairs have gcd as i.\n- gcd[i] - number of pairs which have  gcd equal to i.\n- gcd[i] = divisors[i] * (divisors[i] - 1) / 2 pairs minus the sum of gcd of i\'s multipliers.\n- compute it gcd as prefix sum.\n- do binary search for each query.\n# Code\n```cpp []\nclass Solution {\npublic:\n    vector<int> gcdValues(vector<int>& nums, vector<long long>& queries) {\n        int n = nums.size(), mx = nums[0];\n        for (int i = 0; i < n; i++) \n            mx = max(nums[i], mx);\n        vector<int> divisors(mx+1, 0);\n        vector<long long>gcd(mx+1,0);\n        for (int i = 0; i < n; i++) {\n            for (int j = 1; j <= nums[i] / j; j++) {\n                if (nums[i] % j == 0) {\n                    divisors[j]++;\n                    if (j != nums[i] / j)          \n                        divisors[nums[i] / j]++;\n                }\n            }\n        }\n        for (int i = mx; i >= 1; i--) {\n            gcd[i] = (long long) divisors[i] * (divisors[i] - 1) / 2;\n            for (int j = 2; j <= mx / i; j++) {\n                gcd[i] -= gcd[j * i];\n            }\n        }\n        for (int i = 1; i <= mx; i++) {\n            gcd[i] += gcd[i-1];\n            \n        }\n        vector<int> result;\n        for (int i = 0; i < queries.size(); i++) {\n            auto it = upper_bound(gcd.begin(), gcd.end(), queries[i]);\n            result.push_back(it - gcd.begin());\n            \n        }\n        return result;\n    }\n};\n```
['C++']