Java Easy Solution using HashMap and GCD approach
```\nclass Solution {\n    \n    private int gcd(int a, int b)\n    {\n        if(b % a == 0) return a;\n        \n        return gcd(b % a, a);\n    }\n    \n 
```\nclass Solution {\n    \n    private int gcd(int a, int b)\n    {\n        if(b % a == 0) return a;\n        \n        return gcd(b % a, a);\n    }\n    \n    public long countPairs(int[] nums, int k) {\n        \n        long ans = 0;\n        HashMap<Integer, Integer> map = new HashMap<>();\n        \n        for(int i : nums)\n        {\n            int gcd1 = gcd(i, k);\n            \n            for(int key : map.keySet())\n            {\n                if(((long) gcd1 * key) % k == 0) ans += map.get(key);\n            }\n            \n            map.put(gcd1, map.getOrDefault(gcd1, 0) + 1);\n        }\n        \n        return ans;\n    }\n}
['Java']