C++ O(n*n) time and O(n) space | Unordered Map | Easily Understandable Solution with Explanation
We can easily design brute force using two for loops and checking any pair satisfying given conditions but Time Complexity : O(N2) for brute force Approach!!\n 
* **We can easily design brute force using two for loops and checking any pair satisfying given conditions but** *Time Complexity : O(N2)* for brute force Approach!!\n* **Thus to optimize our approach, we can use hash maps and especially unordered map as we just need to store all elements along with their further occurences in order.**\n* **Unordered map is used here to map first occurence of particular element with all of it\'s occureneces(indices) stored in a vector(list).**\n###  **Time Complexity: O(N * N))**\n\n```\nint countPairs(vector<int>& nums, int k) {\n\tunordered_map<int, vector<int>> mp;\n\tint n = nums.size();\n\n\t// count variable used to track number of possible combinations satisfying given conditions in the question\n\n\tint count = 0;\n\n\tfor(int i=0;i<n;i++){\n\t\t// We use find() method of maps to check any further occurence of our current element in given vector \n\t\tif(mp.find(nums[i]) != mp.end()){\n\t\t\t// Now we can simply iterate over indices of each element stored in vector mapped according to first occurence of each element accordingly stored in our unordered map\n\t\t\tfor(auto x : mp[nums[i]])\n\t\t\t\t// Here, we test each pair of i and x(all next occurences) for conditions given in the Question\n\t\t\t\tif((i * x) % k == 0)\n\t\t\t\t\tcount++;\n\t\t}\n\n\t\t// We push all other occurences after 1st occurence of any element into a seperate vector stored for each element in unordered map mp\n\t\tmp[nums[i]].push_back(i);\n\t}\n\n\treturn count;\n}\n```
['C', 'C++']