✅  C++ Solution GCD with Comments
I tried writing more detailed comments below, hope it helps!\n\nclass Solution {\npublic:\n    long long coutPairs(vector<int>& nums, int k) {\n        unordere
I tried writing more detailed comments below, hope it helps!\n```\nclass Solution {\npublic:\n    long long coutPairs(vector<int>& nums, int k) {\n        unordered_map<int,int> factorCount;\n        long long result =0;\n        int previousIndexCount = 0; // stores any Index that was traversed before\n        for (int i=0;i<nums.size(); i++){\n            int factor = gcd(nums[i], k); // this is the "useful" part of nums[i]\n            int missingFactor = k/factor; // what other factor is needed to form k\n            \n            if (missingFactor==1){ // if missingFactor is 1, the that means nums[i] can match with any previous index to form a pair, k*n %k == 0\n                result += previousIndexCount;\n            }else{ // if m is not 1, we can check if any previous index has the missing factor\n                for (auto it=factorCount.begin(); it!=factorCount.end(); it++){\n                    if ( it->first % missingFactor == 0){\n                        result += it->second;\n                    }\n                }\n            }\n            // only add the "useful" factor part to the map\n            factorCount[factor]++;\n            previousIndexCount++;\n            \n        }\n        return result;\n    }\n};\n```
['C', 'C++']