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. centos6.8安装mysql过程

    1.验证Centos是否安装MySQL $>yum list installed | grep mysql 2.删除MySql $>yum –y remove mysql-libs.X86 ...

  2. (数据科学学习手札52)pandas中的ExcelWriter和ExcelFile

    一.简介 pandas中的ExcelFile()和ExcelWriter(),是pandas中对excel表格文件进行读写相关操作非常方便快捷的类,尤其是在对含有多个sheet的excel文件进行操控 ...

  3. mini dc课堂练习补交

    实验截图 实验代码 import java.util.StringTokenizer; import java.util.Stack; public class MyDC { /** * consta ...

  4. 学号20155311 2016-2017-2 《Java程序设计》第6周学习总结

    学号20155311 2016-2017-2 <Java程序设计>第6周学习总结 教材学习内容总结 第十章 输入/输出 10.1 InputStream与OutputStream Inpu ...

  5. 20155311 实验三 敏捷开发与XP实践 实验报告

    20155311 实验三 敏捷开发与XP实践 实验报告 实验内容 XP基础 xp核心工具 相关工具 实验要求 没有Linux基础的同学建议先学习<Linux基础入门(新版)><Vim ...

  6. PHP学习笔记之interface关键字

    interface用于定义接口 接口里边的方法不需要有方法的实现 implements用于表示类实现某个接口 实现了某个接口之后,必须提供接口中定义的方法的具体实现. 可以用instanceof关键字 ...

  7. WPF中使用WindowChrome自定义窗口中遇到的最大化问题

    FrameWork 4.5 之后,内置了WindowChrome类,官方文档: https://msdn.microsoft.com/en-us/library/system.windows.shel ...

  8. 北京Uber优步司机奖励政策(4月15日)

    滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...

  9. 【转载】C/C++杂记:深入虚表结构

    原文:C/C++杂记:深入虚表结构 1. 虚表与“虚函数表” 在“C/C++杂记:虚函数的实现的基本原理”一文中曾提到“虚函数表”的概念,只是为了便于理解,事实是:虚函数表并不真的独立存在,它只是虚表 ...

  10. day5 RHCE

    19 .配置 iSCSI 服务端  (***先做这个题目**,挂载重启,机器会挂掉) 配置server0提供一个iSCSI服务磁盘名为iqn.2014-11.com.example:server0,并 ...