Python Solution
\tfrom math import gcd\n\t#it is a simple number theory question\n\t# we have taken the prime factorization of any number with respect to the k\n\t# and then we
\tfrom math import gcd\n\t#it is a simple number theory question\n\t# we have taken the prime factorization of any number with respect to the k\n\t# and then we find the second number  by gcd1 \n\tclass Solution:\n\t\tdef countPairs(self, nums: List[int], k: int) -> int:\n\t\t\tcnt=defaultdict(int)\n\t\t\tres=0\n\t\t\tn=len(nums)\n\t\t\tfor i in range(n):\n\t\t\t\tgcd1= gcd(nums[i],k)\n\t\t\t\tgcd2=k//gcd1\n\t\t\t\tif gcd2==1:\n\t\t\t\t\tres+=i\n\t\t\t\telse:\n\t\t\t\t\tfor x,y in cnt.items():\n\t\t\t\t\t\tif x%gcd2==0:\n\t\t\t\t\t\t\tres+=y\n\t\t\t\tcnt[gcd1]+=1\n\t\t\treturn res\n
['Python']