Advertisement
Jaydeep999997

GCD and LCM

Mar 7th, 2021
728
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.91 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long double ld;
  5. typedef long long int ll;
  6. typedef pair<int, int> pi;
  7. typedef pair<long long, long long> pll;
  8.  
  9. #define endl '\n'
  10. #define ff first
  11. #define ss second
  12. #define pb push_back
  13. #define int long long
  14. #define sz(v) (int)v.size()
  15. #define inf 2147483647
  16. #define llinf 9223372036854775807
  17. #define all(v) v.begin(),v.end()
  18. #define bp(n) __builtin_popcountll(n)
  19. #define f(i,l,r) for(long long i=l;i<=r;i++)
  20. #define rf(i,r,l) for(long long i=r;i>=l;i--)
  21. #define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
  22.  
  23. template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
  24. template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
  25. template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
  26.  
  27. void dbg_out() { cerr << endl; }
  28. template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
  29.  
  30.  
  31. const int N = 3e5 + 5, mod = 1e9 + 7, bit = 61;
  32.  
  33. mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  34.  
  35. int getRand(int l, int r)
  36. {
  37.     uniform_int_distribution<int> uid(l, r);
  38.     return uid(rng);
  39. }
  40.  
  41. signed main()
  42. {
  43.     fast;
  44.  
  45.  
  46. #ifndef ONLINE_JUDGE
  47.     freopen("input.txt", "r", stdin);
  48.     freopen("output.txt", "w", stdout);
  49. #endif
  50.  
  51.     int t = 1;
  52.     cin >> t;
  53.     f(tc, 1, t)
  54.     {
  55.         int n;
  56.         cin >> n;
  57.         int a[n];
  58.         f(i, 0, n - 1)
  59.         {
  60.             cin >> a[i];
  61.         }
  62.         sort(a, a + n);
  63.         map<int, int> mp;
  64.         int ans = 0;
  65.         f(i, 0, n - 1)
  66.         {
  67.             mp[a[i]]++;
  68.             if (a[i] % 2 == 0)
  69.             {
  70.                 ans += mp[a[i] / 2];
  71.             }
  72.         }
  73.         cout << ans << endl;
  74.     }
  75.     return 0;
  76. }
  77.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement