class Solution { public: long long countKdivPairs(int A[], int n, int K) { //code here long ans=0; unordered_map<int,int>m; for(int i=0;i<n;i++) { int rem=A[i]%K; if(rem!=0) { ans+=m[K-rem]; } else ans+=m[0]; m[rem]++; } return ans; } };
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter