C++ || EASY TO UNDERSTAND || Simple GCD + HashMap Solution
\n#define ll long long int\nclass Solution {\npublic:\n    long long countPairs(vector<int>& nums, int k) {\n        map<ll,ll> mp;\n        ll n=nums.size();\n
```\n#define ll long long int\nclass Solution {\npublic:\n    long long countPairs(vector<int>& nums, int k) {\n        map<ll,ll> mp;\n        ll n=nums.size();\n        for(ll i=0;i<n;i++)\n        {\n            nums[i]=__gcd(nums[i],k);\n            mp[nums[i]]++;\n        }\n        ll ans=0;\n        for(auto &x:mp)\n        {\n            for(auto &y:mp)\n            {\n                if((x.first*y.first)%k==0)\n                {\n                    if(x.first==y.first)\n                    {\n                        ans+=(mp[x.first]-1)*mp[y.first];   \n                    }\n                    else\n                    {\n                        ans+=(mp[x.first]*mp[y.first]);\n                    }\n                }\n            }\n        }\n        return ans/2;\n    }\n};\n```\n**Please upvote to motivate me in my quest of documenting all leetcode solutions. HAPPY CODING:)\nAny suggestions and improvements are always welcome**\n
[]