-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathabsolute.cpp
47 lines (38 loc) · 851 Bytes
/
absolute.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//{ Driver Code Starts
#include <bits/stdc++.h>
using namespace std;
// } Driver Code Ends
//User function Template for C++
class Solution {
public:
long long countPairs(int n, int arr[], int k) {
// code here
long long res=0;
for(int i=0;i<n;i++){
arr[i] = (arr[i]%k);
}
unordered_map<int,int> mp;
for(int i=0;i<n;i++) mp[arr[i]]++;
for(int i=0;i<k;i++){
res += (mp[i]*(mp[i]-1))/2;
}
return res;
}
};
//{ Driver Code Starts.
int main() {
int t;
cin >> t;
while (t--) {
int n,k;
cin>>n;
int arr[n];
for(int i=0; i<n; i++)
cin>>arr[i];
cin>>k;
Solution ob;
cout << ob.countPairs(n,arr,k) << endl;
}
return 0;
}
// } Driver Code Ends