Codeforces Round 925 (Div. 3) 1931D. Divisible Pairs Solution
Problem Link : https://codeforces.com/contest/1931/problem/D
Solution in C++:
- /// Author : AH_Tonmoy
- #include <bits/stdc++.h>
- using namespace std;
- int32_t main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- int t;
- cin >> t;
- while (t--) {
- int n , x , y ; cin >> n >> x >> y ;
- vector<int>a(n) ;
- long long ans = 0 ;
- map<pair<int,int>,int>mp ;
- for ( int i = 0 ; i < n ; i++){
- cin >> a[i] ;
- ans += mp[{(x-a[i]%x)%x,a[i] % y }] ;
- mp[{a[i]%x , a[i] % y}]++ ;
- }
- cout << ans << '\n' ;
- }
- return 0 ;
- }
No comments