AVS
ChatGPT\n# Code\ncpp []\nclass Solution {\npublic:\n    long long countPairs(vector<int>& a, int k) {\n        long long ans = 0;\n        int n = a.size();\n  
# ChatGPT\n# Code\n```cpp []\nclass Solution {\npublic:\n    long long countPairs(vector<int>& a, int k) {\n        long long ans = 0;\n        int n = a.size();\n        map<int, int> m;  // map to store counts of gcd(a[i], k)\n        \n        for (int i = 0; i < n; i++) {\n            int gcd_a_i_k = gcd(a[i], k);\n            \n            // Now we check for any previous numbers in map m\n            // such that the product of their GCDs is divisible by k\n            for (auto& it : m) {\n                if ((long long)gcd_a_i_k * it.first % k == 0) {\n                    ans += it.second;\n                }\n            }\n            \n            // Add the current gcd(a[i], k) to the map\n            m[gcd_a_i_k]++;\n        }\n\n        return ans;\n    }\n};\n\n```
['C++']