[Java] Counting previous numbers by GCDs
For a given number, only the gcd between current number num[i] and k need to be considered. All we need to do is to count/group the numbers by the gcds. And if 
For a given number, only the gcd between current number `num[i]` and k need to be considered. All we need to do is to count/group the numbers by the gcds. And if `gcd(num[i], k) *  gcd(num[j], k)` is divisible by k , `num[i] * num[j]` should also be divisible.\n\n```\nclass Solution {\n    public long countPairs(int[] nums, int k) {\n        long result = 0;\n        Map<Integer, Integer> gcdMap = new HashMap<>();\n        for (int i = 0; i < nums.length; i++) {\n            int gcd = findGcd(nums[i], k);\n            for (int num : gcdMap.keySet()) {\n                if ((long) gcd * num % k == 0) { // Need to convert gcd(i) * gcd(j) to long, sad java\n                    result += gcdMap.get(num);\n                }\n            }\n            gcdMap.put(gcd, gcdMap.getOrDefault(gcd, 0) + 1);\n        }\n        return result;\n    }\n    private int findGcd(int x, int y) {\n        if (x < y) {\n            return findGcd(y, x);\n        }\n        return y == 0 ? x : findGcd(y, x % y);\n    }\n}\n```
['Java']