Wanted To Share the Kotlin Version
\n# Code\n\nclass Solution {\n    fun countPairs(nums: IntArray, k: Int): Long {\n        val map = HashMap<Long, Long>()\n        var ans = 0L\n        \n     
\n# Code\n```\nclass Solution {\n    fun countPairs(nums: IntArray, k: Int): Long {\n        val map = HashMap<Long, Long>()\n        var ans = 0L\n        \n        fun getGCD(a: Long, b: Long): Long {\n            if (b == 0L)\n                return a\n            return getGCD(b, a % b)\n        }\n        \n        for (i in nums.indices) {\n            val gcd1 = getGCD(nums[i].toLong(), k.toLong())\n            \n            for (key in map.keys) {\n                val gcd2 = key\n                if ((gcd1 * gcd2) % k == 0L) {\n                    ans += map[key] ?: 0L\n                }\n            }\n\n            map[gcd1] = map.getOrDefault(gcd1, 0L) + 1\n        }\n        return ans\n    }\n}\n\n```
['Kotlin']