Advertisement
JouJoy

Untitled

Nov 16th, 2021
1,063
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. #include <iostream>
  2. #include<vector>
  3. #include<algorithm>
  4. #include <map>
  5. #define ll long long
  6. using namespace std;
  7. int main()
  8. {
  9.     int n;
  10.     cin >> n;
  11.     vector<int> a;
  12.     a.resize(n);
  13.     map<ll, ll>mp;
  14.     for (int i = 0; i < n; i++)
  15.     {
  16.         cin >> a[i];
  17.         mp[a[i]]++;
  18.     }
  19.  
  20.     ll pow[32];
  21.     pow[0] = 1;
  22.     for (int i = 1; i < 32; i++) pow[i] = pow[i - 1] * 2;
  23.  
  24.     ll ans = 0;
  25.     for (int i = 0; i < n; i++)
  26.     {
  27.         mp[a[i]]--;
  28.         for (int j = 0; j < 32; j++)
  29.         {
  30.             ll x = pow[j] - a[i];
  31.             if (x > 0 && mp[x] > 0)
  32.                 ans += mp[x];
  33.         }
  34.     }
  35.     cout << ans << endl;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement