Problem Description

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

For example, the following sequences are good:

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

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

For example, the following sequences are not good:

[16] (for a1=16, it is impossible to find another element aj such that their sum is a power of two),
[4,16] (for a1=4, it is impossible to find another element aj such that their sum is a power of two),
[1,3,2,8,8,8] (for a3=2, it is impossible to find another element aj such that their sum is a power of two).
You are given a sequence a1,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≤120000) — the length of the given sequence.

The second line contains the sequence of integers a1,a2,…,an(1≤ai≤10^9).

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

2

Input

1
16

Output

1

Input

4
1 1 1 1023

Output

0

题意:给出 n 个数,对于每个数 ai,要求 ai+aj 都为2的幂,求不符合条件的个数

思路:

要判断是否和为 2 的幂,因此可以贪心的从 2^30 向下进行枚举,如果数组中的每一个数 ai,在数组中存在 j-ai 的话,则证明符合条件,反之则不符合。

因为题目的数据范围较大,因此用 map 存储。

Source Program

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<ctime>
#include<vector>
#define INF 0x3f3f3f3f
#define PI acos(-1.0)
#define N 1000005
#define MOD 123
#define E 1e-6
using namespace std;
map<long long,long long> mp;
map<long long,bool>vis;
long long a[N];
int main()
{int n;cin>>n;for(int i=0;i<n;i++){cin>>a[i];mp[a[i]]++;}sort(a,a+n);int cnt=0;for(int i=0;i<n;i++){if(vis[a[i]])continue;bool flag=true;for(long long j=1<<30;j>=1;j>>=1){if(j<a[i])break;if(mp.count(j-a[i])){if(j-a[i]==a[i]&&mp[j-a[i]]==1)continue;vis[a[i]]=1;vis[j-a[i]]=1;flag=false;break;}}if(flag)cnt++;}cout<<cnt<<endl;return 0;
}

Summarize to the Power of Two(CF-1005C)相关推荐

  1. D. Make a Power of Two(cf#739DIV3)

    D. Make a Power of Two 链接: link. 题意: 找出将数字转换为 2 的任意幂的最小移动次数. 题解: 先将2的xxx次幂的结果以字符串形式保存,输入字符串nnn后,因为存在 ...

  2. 【SPOJ】Power Modulo Inverted(拓展BSGS)

    [SPOJ]Power Modulo Inverted(拓展BSGS) 题面 洛谷 求最小的\(y\) 满足 \[k\equiv x^y(mod\ z)\] 题解 拓展\(BSGS\)模板题 #inc ...

  3. 2019牛客多校第九场AThe power of Fibonacci(广义BM)

    2019牛客多校第九场AThe power of Fibonacci(广义BM) 题目大意 求斐波那契数列m次方的前n项和 解题思路 显然,斐波那契的m次方前缀和依然是线性递推,因此考虑用exBM求解 ...

  4. 【我所认知的BIOS】—Advanced Configuration and Power Interface原理(硬件部分)

    [我所认知的BIOS]->Advanced Configuration and Power Interface原理(硬件部分) LightSeed 2/24/2014 ACPI是一个内容很丰富的 ...

  5. 【解题报告】随便练练二(CF 2300)

    [解题报告]随便练练二(CF 2300) A:Antimatter | CF383D 题意 思路 :DP 代码 B:Physical Education Lessons | CF915E 题意 思路一 ...

  6. Commentator problem(CF 2)

    题目链接 题目大意: 给定三个圆,询问是否存在点满足该点与三个圆夹角均相等,若存在多组解返回夹角最大值. 圆外一点到两圆夹角均相等: 即 sina = sinb = r1 / d1 = r2 / d2 ...

  7. [leetcode]326. Power of Three(c语言)

    题目 Given an integer, write a function to determine if it is a power of three. Follow up: Could you d ...

  8. 2021 CCPC 哈尔滨 E. Power and Modulo (思维题)

    Problem - E - Codeforces 思路: 这个题搞清楚那几种情况,特判一下第一个数,需要注意的是不能简单直接的按照题意使用 pow(2,n - 1),这样会wa,因为n是1e5的数量级 ...

  9. 建立第一个Power Apps程序(新手版)

    跟据下列地址完成PowerBI Apps的账户注册: Power Apps注册账户 - qq_16313575的博客 - CSDN博客 https://blog.csdn.net/qq_1631357 ...

最新文章

  1. 1059 Prime Factors
  2. python用字典存储学生信息网_用Python存储字典的四种方法
  3. 利用微信的weui框架上传、预览和删除图片
  4. Keil uVision4 for ARM 下增加支持C51,C5x
  5. 一眼中毒!雷军晒小米9官方高清真机图:全息幻彩惊艳无比
  6. mysql 树形结构_Mysql安装:基础入门知识
  7. mysql分组和where条件查询,mysql中where和having条件查询的区别
  8. 新版FMEA软件参数图(P图)简介(FMEAHunter)
  9. 手把手教你玩转QQ的原创表情
  10. vscode 设置中文语言包
  11. Readyboost技术U 盘变内存,加速电脑(只针对Windows 7和Vista系统)
  12. ESP8266 +0.96“ I2C OLED 表盘时钟
  13. Android水波纹效果
  14. 办公室网络带宽叠加(有线和WiFi同时使用)
  15. 异步时间扭曲(Asynchronous Timewarp简称ATW)一种生成中间帧技术
  16. 不交智商税,如何判断一场知乎live的质量?
  17. python list diff_Python List交集,并集,差集的应用
  18. java输入一个年份,利用Java实现从键盘输入一个年份,程序输出改年出生的人的生肖...
  19. luogu P5320 [BJOI2019]勘破神机
  20. 计算机网络安全工作室介绍,计算机网络技术专业 “网络工作室”做法简介

热门文章

  1. 未来10年,最具颠覆性的5大指数型技术(附应用建议)
  2. 屏幕小于6英寸的手机_vivo新机成最轻薄手机?6.56英寸屏幕,重量仅178g
  3. python svm 决策方程_python – 使用scikit-learn线性SVM提取决策边界
  4. 从实际业务中来,到落地业务建模中去
  5. Linux 给新用户授予、设置Tomcat目录的使用权限
  6. 【JEECG技术博文】JEECG图表配置说明
  7. su 切换,提示:“密码不正确”;
  8. 深度可分离卷积(Xception 与 MobileNet)
  9. Hadoop本地运行模式了解~
  10. 【干货】Kafka实现淘宝亿万级数据统计(上)