简单题。
开一个$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-8; 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 = 0;while(!isdigit(c)) c = getchar(); while(isdigit(c)) { x = x * 10 + c - '0'; c = getchar(); } } const int maxn=100010; LL a[maxn],ans; map<LL,int>f; int n; int main() { scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%lld",&a[i]),f[a[i]]++; for(int i=1;i<=n;i++) { f[a[i]]--; LL sum=1; for(int j=0;j<=32;j++) { ans=ans+f[sum-a[i]]; sum=sum*2; } } printf("%lld\n",ans); return 0; }