Problem link:http://codeforces.com/contest/702/problem/B
#include<bits/stdc++.h>
using namespace std;
long long ar[100009];
int main()
{
map<long long,long long>mp;
long long n,i,sum,f,c,j,p,s;
while(cin>>n)
{
for(i=0; i<n; i++)
{
scanf("%I64d",&ar[i]);
mp[ar[i]]++;
//printf("%I64d\n",mp[ar[i]]);
}
sum=0;
for(i=0; i<n; i++)
{
mp[ar[i]]--;
for(j=1;j<=31;j++)
{
p=1<<j;
s=p-ar[i];
//printf("%I64d\n",s);
if(mp[s])
sum+=mp[s];
}
}
printf("%I64d\n",sum);
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
long long ar[100009];
int main()
{
map<long long,long long>mp;
long long n,i,sum,f,c,j,p,s;
while(cin>>n)
{
for(i=0; i<n; i++)
{
scanf("%I64d",&ar[i]);
mp[ar[i]]++;
//printf("%I64d\n",mp[ar[i]]);
}
sum=0;
for(i=0; i<n; i++)
{
mp[ar[i]]--;
for(j=1;j<=31;j++)
{
p=1<<j;
s=p-ar[i];
//printf("%I64d\n",s);
if(mp[s])
sum+=mp[s];
}
}
printf("%I64d\n",sum);
}
return 0;
}
No comments:
Post a Comment