A sequence a1,a2,…,ana1,a2,…,an is called good if, for each element aiai, there exists an element ajaj (i≠ji≠j) such that ai+ajai+aj is a power of two (that is, 2d2d for some non-negative integer dd).

For example, the following sequences are good:

  • [5,3,11][5,3,11] (for example, for a1=5a1=5 we can choose a2=3a2=3. Note that their sum is a power of two. Similarly, such an element can be found for a2a2 and a3a3),
  • [1,1,1,1023][1,1,1,1023],
  • [7,39,89,25,89][7,39,89,25,89],
  • [][].

Note that, by definition, an empty sequence (with a length of 00) is good.

For example, the following sequences are not good:

  • [16][16] (for a1=16a1=16, it is impossible to find another element ajaj such that their sum is a power of two),
  • [4,16][4,16] (for a1=4a1=4, it is impossible to find another element ajaj such that their sum is a power of two),
  • [1,3,2,8,8,8][1,3,2,8,8,8] (for a3=2a3=2, it is impossible to find another element ajaj such that their sum is a power of two).

You are given a sequence a1,a2,…,ana1,a2,…,an. What is the minimum number of elements you need to remove to make it good? You can delete an arbitrary set of elements.

Input

The first line contains the integer nn (1≤n≤1200001≤n≤120000) — the length of the given sequence.

The second line contains the sequence of integers a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109).

Output

Print the minimum number of elements needed to be removed from the given sequence in order to make it good. It is possible that you need to delete all nn elements, make it empty, and thus get a good sequence.

Examples
input
6
4 7 1 5 4 9
output
1
input
5
1 2 3 4 5
output

Copy
2
input
1
16
output
1
input
4
1 1 1 1023
output
0
Note

In he first example, it is enough to delete one element a4=5. The remaining elements form the sequence [4,7,1,4,9][4,7,1,4,9], which is good.

题目意思:给你一个数列,然后让你删掉某个数,让每一个数都可以与另外一个数相加,之和等于2的^d次方,问最少删掉的个数

解题思路:先预处理出2的次幂,然后暴力枚举出每个数与每个2的次幂之差,去判断在map中是否有这样的差存在(注意相同的两个数,比如4 ,4   这个时候就可以特判一下,出现次数),若不存在那么就需要删除掉这个数。

 #include<cstdio>
#include<cstring>
#include<map>
#include<algorithm>
#define ll long long int
using namespace std;
ll d[];
ll a[];
map<ll,ll>mp;
void double_2()
{
int i;
d[]=;
for(i=; i<=; i++)
{
d[i]=d[i-]*;
}
}
int main()
{
int i,j,flag,n;
ll k;
double_2();///2的幂
while(scanf("%d",&n)!=EOF)
{
int count=;
mp.clear();///map清零
for(i=; i<n; i++)
{
scanf("%lld",&a[i]);
mp[a[i]]++;///记录出现的次数
}
for(i=; i<n; i++)
{
flag=;
for(j=; j<=; j++)
{
if(a[i]>=d[j])
{
continue;
}
else
{
k=d[j]-a[i];
if(mp[k])///map中存在
{
if(a[i]==k)
{
if(mp[k]>=)///map中需要至少两个
{
flag=;
break;
}
}
else
{
flag=;
break;
}
}
}
}
if(!flag)
{
count++;
}
}
printf("%d\n",count);
}
return ;
}

Summarize to the Power of Two(map+思维)的更多相关文章

  1. CF1005C Summarize to the Power of Two 暴力 map

    Summarize to the Power of Two time limit per test 3 seconds memory limit per test 256 megabytes inpu ...

  2. CF 1005C Summarize to the Power of Two 【hash/STL-map】

    A sequence a1,a2,-,an is called good if, for each element ai, there exists an element aj (i≠j) such ...

  3. [USACO12NOV]同时平衡线Concurrently Balanced Strings DP map 思维

    题面 [USACO12NOV]同时平衡线Concurrently Balanced Strings 题解 考虑DP. \(f[i]\)表示以\(i\)为左端点的合法区间个数.令\(pos[i]\)表示 ...

  4. Bracket Sequences Concatenation Problem括号序列拼接问题(栈+map+思维)

    A bracket(括号) sequence is a string containing only characters "(" and ")".A regu ...

  5. Codeforces 755B:PolandBall and Game(map+思维)

    http://codeforces.com/problemset/problem/755/B 题意:A可以喊出n个字符串,B可以喊出m个字符串,如果一个字符串之前被喊过,那么它再也不能喊了,A先喊,最 ...

  6. mind map 思维导图

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  7. HDU 6623 Minimal Power of Prime(思维)题解

    题意: 已知任意大于\(1\)的整数\(a = p_1^{q_1}p_2^{q_2} \cdots p_k^{q_k}\),现给出\(a \in [2,1e18]\),求\(min\{q_i\},q ...

  8. IDE引入mindmap插件,在项目中添加思维导图

    1.打开IDE,file--settings--plugins,搜索IDEA Mind Map 2.点击install,进行下载,然后按照提示restart重启IDEA,安装完成 3.创建mind m ...

  9. Codeforces Round #496 (Div. 3) ABCDE1

    //B. Delete from the Left #include <iostream> #include <cstdio> #include <cstring> ...

随机推荐

  1. java spring-WebSocket json参数传递与接收

    Websocket原理(摘抄) 一.websocket与http WebSocket是HTML5出的东西(协议),也就是说HTTP协议没有变化,或者说没关系,但HTTP是不支持持久连接的(长连接,循环 ...

  2. java核心技术-多线程之线程内存模型

    对于每一种编程语言,理解它的内存模型是理所当然的重要.下面我们从jvm的内存模型来体会下java(不限java语言,严格来讲是JVM内存模型,所有JVM体系的变成语言均适用)的内存模型. 堆: 就是我 ...

  3. C++程序设计入门(上) 函数学习

    局部变量和全局变量的访问: 全局变量的作用域时全局,局部变量的作用域是局部,若全局和局部的变量名相同的话,局部变量的改变不会引起全局变量的改变#include<iostream> int ...

  4. ztz11的noip模拟赛T1:愤怒的XiaoX

    链接: https://www.luogu.org/problemnew/show/U47231 思路: 这道题其实就是一道双Lazy线段树裸题 因为我们知道,当k一定时,取反偶数次最后k位等于不取反 ...

  5. linux查看网卡地址和硬盘序列号

    linux查看网卡地址命令:ifconfig linux查看硬盘序列号命令:hdparm -i /dev/sda

  6. Python中级 —— 06SMTP发送电子邮件

    Email的历史比Web还要久远,直到现在,Email也是互联网上应用非常广泛的服务.(未完)

  7. ruby安装devkit

    双击下载文件,指定解压路径,路径中不能有空格.如C:\DevKit,这个路径就是<DEVKIT_INSTALL_DIR>. > cd <DEVKIT_INSTALL_DIR&g ...

  8. Linux入门进阶第四天(下)——程序管理(补充内容)

    1.PID 触发任何一个事件时,系统都会将他定义成为一个程序,并且给予这个程序一个 ID ,称为 PID,同时依据启发这个程序的使用者与相关属性关系,给予这个 PID 一组有效的权限设置. 同一个程序 ...

  9. 20155207 实验四 《Android程序设计》实验报告

    20155207 实验四 <Android程序设计>实验报告 实验名称 Android程序设计 实验内容 1.Android Stuidio的安装测试: 参考<Java和Androi ...

  10. 实验四android开发基础

    实验四android开发基础 提交点一 Android Stuidio的安装测试: 参考<Java和Android开发学习指南(第二版)(EPUBIT,Java for Android 2nd) ...