#include <bits/stdc++.h>
using namespace std;
vector<long long int> vec;
map<long long int, long long int> mp;
int main() {
  long long int x = 0, y = 0, z = 0, sum = 0;
  cin >> x;
  for (int i = 0; i < x; i++) {
    cin >> y;
    vec.push_back(y);
    mp[y]++;
  }
  sort(vec.begin(), vec.end());
  for (int i = 0; i < vec.size(); i++) {
    for (int j = 0; j <= 30; j++) {
      z = powl(2, j) - vec[i];
      if (binary_search(vec.begin() + i + 1, vec.end(), z) == true) {
        if (z == vec[i]) {
          sum += --mp[z];
        } else {
          sum += mp[z];
        }
      }
    }
  }
  cout << sum << endl;
}
