Faster version
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:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```java []\nclass Solution {\npublic long countPairs(int[] nums, int k) {\n        HashMap<Integer, Integer> gcdCount = new HashMap<>();\n        long count = 0;\n\n        for (int num : nums) {\n            int gcdNum = gcd(num, k);\n\n            for (int factor : gcdCount.keySet()) {\n                if ((long) gcdNum * factor % k == 0) {\n                    count += gcdCount.get(factor);\n                }\n            }\n\n            gcdCount.put(gcdNum, gcdCount.getOrDefault(gcdNum, 0) + 1);\n        }\n\n        return count;\n    }\n\n    // Helper function to calculate GCD\n    private int gcd(int a, int b) {\n        while (b != 0) {\n            int temp = b;\n            b = a % b;\n            a = temp;\n        }\n        return a;\n    }\n}\n```
['Java']