Find factors of each number and store in an array
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:O(n*sqrt(n))\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nclass Solution {\npublic:\n#define ll long long\nvoid findFactors(vector<int>&factors,int n) {\n    for (int i = 1; i <=sqrt(n); ++i) {\n        if (n % i == 0) {\n            factors.push_back(i); \n            if (i != n / i) {\n                factors.push_back(n / i);\n            }\n        }\n    }    \n  sort(factors.begin(), factors.end(),greater<int>());\n}\n\nvector<int> gcdValues(vector<int>& nums, vector<long long>& queries) {\n    int mx=*max_element(nums.begin(),nums.end());\n    int n=nums.size();\n    vector<ll>fact(mx+1,0),gcd(mx+1,0);\n    vector<int>v;\n\n    for(auto i:nums){\n        vector<int>v;findFactors(v,i);\n        for(auto j:v)fact[j]++;\n    }        \n\n    for(int i=mx;i>=1;i--){\n        gcd[i]=(fact[i]*(fact[i]-1))/2;\n        for(int j=2*i;j<=mx;j+=i){\n            gcd[i]-=gcd[j];\n        }\n    }   \n    for(int i=1;i<=mx;i++)gcd[i]+=gcd[i-1];\n    for(auto q:queries){\n        int lb=(lower_bound(gcd.begin(),gcd.end(),q+1)-gcd.begin());\n        v.push_back(lb);\n    }    \n    return v;\n    }\n};\n\n\n```
['C++']