2183. Count Array Pairs Divisible by K.cpp
Code\n\nclass Solution {\npublic:\n    long long countPairs(vector<int>& nums, int k) {\n        vector<int> factors; \n        for (int x = 1; x <= sqrt(k); ++
**Code**\n```\nclass Solution {\npublic:\n    long long countPairs(vector<int>& nums, int k) {\n        vector<int> factors; \n        for (int x = 1; x <= sqrt(k); ++x) \n            if (k % x == 0) factors.push_back(x); \n        long long ans = 0; \n        unordered_map<int, int> freq; \n        for (auto& x : nums) {\n            x = gcd(x, k); \n            ans += freq[k/x]; \n            for (auto& f : factors) \n                if (x % f == 0 && f <= x/f) {\n                    ++freq[f]; \n                    if (f < x/f) ++freq[x/f]; \n                }\n        }\n        return ans; \n    }\n};\n```
['C']