CodeForces1005C.Summarize to the Power of Two(2次幂位运算枚举暴力)

CodeForces1005C.Summarize to the Power of Two(2次幂位运算枚举暴力)
CodeForces1005C.Summarize to the Power of Two(2次幂位运算枚举暴力)

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<cmath>
#include<cctype>
using namespace std;

#define PI acos(-1.0)
#define mp make_pair
#define forn(i,n) for(int i=0;i<n;i++)
#define for1(i,n) for(int i=1;i<=n;i++) 
#define rep(i,a,n)  for(int i=a;i<n;i++)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int INF32M=0x3f3f3f3f;
const ll INF64M=0x3f3f3f3f3f3f3f3f;
const int maxn=2e5+5;
const int mod=1e9+7;

int gcd(int a,int b)
{
	return b!=0?gcd(b,a%b):a;
}
int a[120005];
map<int,int> m;//与值出现次数有关  4 7 1 4 9 (4 7 1 9)4出现1次 不行 出现两次才能凑8 
int main()//值1-1e9 值出现次数 数组爆1e6 只能用map 
{
	ios::sync_with_stdio(false);
	int n,flag=0,cnt=0;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		m[a[i]]++;
	}
	for(int i=1;i<=n;i++)
	{
		flag=0;	//每个a[i]能否找到差值 
		for(int j=1<<30;j>=1;j/=2)	//int 32位除符号31位 最大二次幂 1后30个0 1e9<2^28 
		{
			if(j>a[i])	//大-小 
			{
				if((a[i]==j/2 && m[j-a[i]]>1) || (a[i]!=j/2 && m[j-a[i]]>0))//8-4=4 一半至少出现2次 其余差值1次 8-7=1 
				{
					flag=1;	//次元素找到差值匹配 在数组中存在 
					break;
				}
			}
		}
		if(flag==0)	//for循环走完 找不到 该删除 
			cnt++;
	}
	cout<<cnt<<endl;
	return 0;
}