JAVA | GCD | Simple Solution
\nclass Solution {\n    \n    int gcd(int a, int b){\n        if (a == 0)\n            return b;\n        return gcd(b % a, a);\n    }\n    \n    public long co
```\nclass Solution {\n    \n    int gcd(int a, int b){\n        if (a == 0)\n            return b;\n        return gcd(b % a, a);\n    }\n    \n    public long coutPairs(int[] nums, int k) {\n        int n = nums.length;\n        Map<Long, Long> map = new HashMap<>();\n        for(int num: nums){\n            long key = (long)gcd(num, k);\n            map.put(key, map.getOrDefault(key, 0l)+1l);\n        }\n        System.out.println(map.toString());\n        \n        long count = 0l;\n        Set<String> set = new HashSet<>();\n        for(long k1: map.keySet()){\n            for(long k2: map.keySet()){\n                String str = k2+"$"+k1;\n                if(k1>k2) str = k1+"$"+k2;\n                \n                if(k1!=k2 && !set.contains(str) && (k1*k2)% k == 0){\n                    set.add(str);\n                    count += map.get(k1)*map.get(k2);\n                }\n            }\n        }\n        \n        for(long k1: map.keySet()){\n            if((k1*k1)%k == 0){\n                long val = map.get(k1);\n                count += (val)*(val-1)/2;\n            }\n        }\n        \n        return count;\n        \n    }\n}\n```
['Java']