Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include<vector>
- #include<algorithm>
- #include <map>
- #define ll long long
- using namespace std;
- int main()
- {
- int n;
- cin >> n;
- vector<int> a;
- a.resize(n);
- map<ll, ll>mp;
- for (int i = 0; i < n; i++)
- {
- cin >> a[i];
- mp[a[i]]++;
- }
- ll pow[32];
- pow[0] = 1;
- for (int i = 1; i < 32; i++) pow[i] = pow[i - 1] * 2;
- ll ans = 0;
- for (int i = 0; i < n; i++)
- {
- mp[a[i]]--;
- for (int j = 0; j < 32; j++)
- {
- ll x = pow[j] - a[i];
- if (x > 0 && mp[x] > 0)
- ans += mp[x];
- }
- }
- cout << ans << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement