简单题。
开一个$map$记录一下每个数字出现了几次,那么读入的时候$f[a[i]]+1$。
计算$a[i]$做出的贡献的时候,先把$f[a[i]]-1$,然后再枚举$x$,答案加上$f[{2^x} - a[i]]$。
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-;
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
}
template <class T>
inline void read(T &x)
{
char c = getchar(); x = ;while(!isdigit(c)) c = getchar();
while(isdigit(c)) { x = x * + c - ''; c = getchar(); }
} const int maxn=;
LL a[maxn],ans;
map<LL,int>f;
int n; int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++) scanf("%lld",&a[i]),f[a[i]]++;
for(int i=;i<=n;i++)
{
f[a[i]]--; LL sum=;
for(int j=;j<=;j++)
{
ans=ans+f[sum-a[i]];
sum=sum*;
}
}
printf("%lld\n",ans);
return ;
}