GCD + Math || Beats 50% || Easy to understand || C++
Complexity\n- Time complexity:O(nlogn)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity:O(n)\n Add your space complexity here, e.g. O(n) \n\n# 
# Complexity\n- Time complexity:$$O(nlogn)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:$$O(n)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int mp[100005], freq[100005];\n    long long countPairs(vector<int>& nums, int k) {\n        int n = nums.size();\n        for(int i=0; i<n; i++) mp[nums[i]]++;\n        for(int i=1; i<=100000; i++){\n            for(int j=i; j<=100000; j+=i){\n                freq[i] += mp[j];\n            }\n        }\n        long long ans = 0;\n        for(int i=0; i<n; i++){\n            int q = __gcd(nums[i], k);\n            int val = k / q;\n            ans += freq[val];\n            if(nums[i] % val == 0) ans--;\n        }\n        return ans / 2;\n    }\n};\n```
['C++']