In Java
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```\nimport java.util.HashMap;\nimport java.util.Map;\n\nclass Solution {\n    public long countPairs(int[] nums, int k) {\n        Map<Integer, Integer> gcdCount = new HashMap<>();\n        long count = 0;\n\n        for (int num : nums) {\n            int gcdVal = gcd(num, k);\n            for (int key : gcdCount.keySet()) {\n                if ((long) gcdVal * key % k == 0) {\n                    count += gcdCount.get(key);\n                }\n            }\n            gcdCount.put(gcdVal, gcdCount.getOrDefault(gcdVal, 0) + 1);\n        }\n\n        return count;\n    }\n\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']