fork(1) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. // Speed
  5. #define fast_io ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
  6.  
  7. // Typedefs
  8. #define int long long
  9. #define pb push_back
  10. #define ff first
  11. #define ss second
  12. #define all(x) (x).begin(), (x).end()
  13. #define rall(x) (x).rbegin(), (x).rend()
  14. #define sz(x) ((int)(x).size())
  15. #define endl '\n'
  16. #define yes cout << "yes\n"
  17. #define no cout << "no\n"
  18.  
  19. // Loops
  20. #define rep(i,a,b) for(int i=a;i<b;++i)
  21. #define per(i,a,b) for(int i=b-1;i>=a;--i)
  22. #define each(x, a) for (auto& x : a)
  23.  
  24. // Consts
  25. const int INF = 1e18;
  26. const int MOD = 1e9+7;
  27. const int N = 2e5 + 5;
  28.  
  29. // Math
  30. int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
  31. int lcm(int a, int b) { return (a / gcd(a, b)) * b; }
  32.  
  33. int power(int a, int b, int m = MOD) {
  34. int res = 1;
  35. while (b > 0) {
  36. if (b & 1) res = res * a % m;
  37. a = a * a % m;
  38. b >>= 1;
  39. }
  40. return res;
  41. }
  42.  
  43. int modinv(int a, int m = MOD) {
  44. return power(a, m - 2, m);
  45. }
  46.  
  47. // Logic
  48. void solve() {
  49. // Code
  50. int n,x,y;
  51. cin>>n>>x>>y;
  52. vector <int>a(n);
  53. rep(i,0,n) cin>>a[i];
  54. int count=0;
  55. map<pair<int,int>,int>p;
  56. rep(i,0,n){
  57. int rx=a[i]%x;
  58. int ry=a[i]%y;
  59. int rxr=(x-rx)%x;
  60. int ryr=ry%y;
  61. if(p.count({rxr,ryr})){
  62. count+=p.count({rxr,ryr});
  63. }
  64. p[{rx,ry}]++;
  65. }
  66. cout<<count<<endl;
  67. }
  68.  
  69. // Main
  70. int32_t main() {
  71. fast_io;
  72.  
  73. int t;
  74. cin >> t;
  75. while (t--) {
  76. solve();
  77. }
  78.  
  79. return 0;
  80. }
  81.  
Success #stdin #stdout 0.01s 5288KB
stdin
7
6 5 2
1 2 7 4 9 6
7 9 5
1 10 15 3 8 12 15
9 4 10
14 10 2 2 11 11 13 5 6
9 5 6
10 7 6 7 9 7 7 10 10
9 6 2
4 9 7 1 2 2 13 3 15
9 2 3
14 6 1 15 12 15 8 2 15
10 5 7
13 3 3 2 12 11 3 7 13 14
stdout
2
0
1
2
4
5
0