#include <bits/stdc++.h>
using namespace std;
const int maxn = 100100;
int n;
long long a[maxn];
map<long long, long long> mp;
long long mul(long long x, long long n) {
  long long ret = 1;
  while (n) {
    if (n & 1) ret *= x;
    x *= x;
    n >>= 1;
  }
  return ret;
}
int main() {
  while (~scanf("%d", &n)) {
    mp.clear();
    for (int i = (1); i < (n + 1); i++) {
      cin >> a[i];
      mp[a[i]]++;
    }
    long long ret = 0;
    for (int i = (1); i < (n + 1); i++) {
      for (int j = 0; j < (31); j++) {
        long long cur = mul(2, j);
        if (mp.find(cur - a[i]) != mp.end()) {
          if (mp[cur - a[i]] == 1 && cur - a[i] == a[i])
            continue;
          else if (mp[cur - a[i]] > 1 && cur - a[i] == a[i])
            ret += mp[cur - a[i]] - 1;
          else
            ret += mp[cur - a[i]];
        }
      }
    }
    cout << ret / 2 << endl;
  }
  return 0;
}
