EASY BEGINNER CODE USING GCD
Intuition\nJust a gcd easy math solution ;\n\n# Approach\nread the comments in the code u will understand the code\n**Bold****\n\n# Complexity\n- Time complexit
# Intuition\nJust a gcd easy math solution ;\n\n# Approach\nread the comments in the code u will understand the code\n******Bold******\n\n# Complexity\n- Time complexity:\nO(n\u22C5sqrt(k))\n\n- Space complexity:\nO(n)\n\n# Code\n```\nclass Solution {\npublic:\n    long long countPairs(vector<int>& nums, int k) {\n        int n=nums.size();\n        unordered_map<int,int>mp;\n        long long int ans =0;\n        for(int i=0;i<n;i++){\n            int one_factor=__gcd(nums[i],k);\n            int other_factor=(k/one_factor);\n            if(other_factor==1){   // suppose k=axbxcand gcd(k,nums[i])-->axb so k/gcd(k,nums[i])==axbxcxd/axb---->bxc and if bxc==1 then nums[i] can be paired with any previous element kyuki ,,,,, its dividing the k fully by itself and left nothing for other element to handle ;\n\n                ans+=i;\n\n            }\n\n            else{\n                for(auto it:mp){\n                    if(it.first%other_factor==0){\n                        ans+=it.second;\n                    }\n                }\n\n            }\n            mp[one_factor]++;\n\n        }\n        return ans;\n\n    }\n};\n```
['C++']