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. centos7 安装mysql5.7以及一些细节问题

    突然发现我的新服务器上没有mysql,所以想安装一个,上次在我的window电脑上安装MySQL8.0我真的要气死了,和5.7修改密码的方式不一样,弄了很久,所以我决定还是不用安装8.0了,5.7就可 ...

  2. hadoop docker集群搭建

    获取镜像 #本机内 docker pull ubuntu:16.04 编排镜像 启动一个容器 #本机内 docker run -i -t --name master ubuntu:16.04 在容器内 ...

  3. HTML5新增元素,标签总结

    总是遇到h5新标签的笔试题目,就查阅了资料来总结一下: 1.form相关: (1)form属性:在HTML5中表单元素可放在表单之外,通过给该元素添加form属性来指向目标表单(form属性值设为目标 ...

  4. 111. Climbing Stairs 【LintCode easy】

    Description You are climbing a stair case. It takes n steps to reach to the top. Each time you can e ...

  5. 20155210 潘滢昊 Java第一次实验---凯撒密码

    Java第一次实验---凯撒密码 实验内容 实现凯撒密码,并进行测试. 实验代码 import java.io.*; import java.util.Scanner; public class ks ...

  6. 20155231 信息安全技术概论实验二 Windows口令破解

    20155231 信息安全技术概论实验二 Windows口令破解 实验目的 了解Windows口令破解原理 对信息安全有直观感性认识 能够运用工具实现口令破解 实验人数 每组一人 系统环境 windo ...

  7. 20155308 2016-2017-2 《Java程序设计》实验二 Java面向对象程序设计

    20155308 2016-2017-2 <Java程序设计>实验二 Java面向对象程序设计 实验内容 初步掌握单元测试和TDD 理解并掌握面向对象三要素:封装.继承.多态 初步掌握UM ...

  8. # 2016-2017-2 20155319 《Java程序设计》实验四Android程序开发实验报告

    2016-2017-2 20155319 <Java程序设计>实验四Android程序开发实验报告 实验一 实验内容 Android Stuidio的安装测试: 参考<Java和An ...

  9. Centos安装man功能

    CentOS接触很久了,但是一直作为服务器端使用.这次之所以安装man,是由于开始学习Nginx了. 言归正传,安装man,首先得下载包.由于我们天朝的原因,代码包几乎下不到的.首先你得FQ,再下载, ...

  10. 15、Java并发编程:Callable、Future和FutureTask

    Java并发编程:Callable.Future和FutureTask 在前面的文章中我们讲述了创建线程的2种方式,一种是直接继承Thread,另外一种就是实现Runnable接口. 这2种方式都有一 ...