题目链接:

B. Powers of Two

time limit per test

3 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given n integers a1, a2, ..., an. Find the number of pairs of indexes i, j (i < j) that ai + aj is a power of 2 (i. e. some integer xexists so that ai + aj = 2x).

Input

The first line contains the single positive integer n (1 ≤ n ≤ 105) — the number of integers.

The second line contains n positive integers a1, a2, ..., an (1 ≤ ai ≤ 109).

Output

Print the number of pairs of indexes i, j (i < j) that ai + aj is a power of 2.

Examples
input
4
7 3 2 1
output
2
input
3
1 1 1
output
3

题意:
问有多少对a[i]+a[j]是2的次幂; 思路: map搞一搞; AC代码:
/************************************************
┆ ┏┓   ┏┓ ┆
┆┏┛┻━━━┛┻┓ ┆
┆┃       ┃ ┆
┆┃   ━   ┃ ┆
┆┃ ┳┛ ┗┳ ┃ ┆
┆┃       ┃ ┆
┆┃   ┻   ┃ ┆
┆┗━┓   ┏━┛ ┆
┆  ┃   ┃  ┆      
┆  ┃   ┗━━━┓ ┆
┆  ┃  AC代马   ┣┓┆
┆  ┃    ┏┛┆
┆  ┗┓┓┏━┳┓┏┛ ┆
┆   ┃┫┫ ┃┫┫ ┆
┆   ┗┻┛ ┗┻┛ ┆
************************************************ */ #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <bits/stdc++.h>
#include <stack> using namespace std; #define For(i,j,n) for(int i=j;i<=n;i++)
#define mst(ss,b) memset(ss,b,sizeof(ss)); typedef long long LL; template<class T> void read(T&num) {
char CH; bool F=false;
for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
F && (num=-num);
}
int stk[70], tp;
template<class T> inline void print(T p) {
if(!p) { puts("0"); return; }
while(p) stk[++ tp] = p%10, p/=10;
while(tp) putchar(stk[tp--] + '0');
putchar('\n');
} const LL mod=1e9+7;
const double PI=acos(-1.0);
const int inf=1e9;
const int N=1e5+10;
const int maxn=(1<<8);
const double eps=1e-8; int a[N],cnt=0,b[50]; map<int,int>mp,vis; inline void Init()
{
LL temp=2;
while(temp<=2e9+100)
{
b[++cnt]=(int)temp;
temp=temp*2;
}
}
int main()
{ Init();
int n;
read(n);
For(i,1,n)read(a[i]),mp[a[i]]++,vis[a[i]]=1;
LL ans=0;
For(i,1,n)
{
For(j,1,cnt)
{
if(vis[b[j]-a[i]])
{
int x=b[j]-a[i];
if(x==a[i])
{
ans=ans+mp[x]-1;
}
else
{
ans=ans+mp[x];
}
}
}
}
cout<<ans/2<<endl; return 0;
}

  

codeforces 702B B. Powers of Two(水题)的更多相关文章

  1. Educational Codeforces Round 7 B. The Time 水题

    B. The Time 题目连接: http://www.codeforces.com/contest/622/problem/B Description You are given the curr ...

  2. Educational Codeforces Round 7 A. Infinite Sequence 水题

    A. Infinite Sequence 题目连接: http://www.codeforces.com/contest/622/problem/A Description Consider the ...

  3. Codeforces Testing Round #12 A. Divisibility 水题

    A. Divisibility Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/probl ...

  4. Codeforces Beta Round #37 A. Towers 水题

    A. Towers 题目连接: http://www.codeforces.com/contest/37/problem/A Description Little Vasya has received ...

  5. codeforces 677A A. Vanya and Fence(水题)

    题目链接: A. Vanya and Fence time limit per test 1 second memory limit per test 256 megabytes input stan ...

  6. CodeForces 690C1 Brain Network (easy) (水题,判断树)

    题意:给定 n 条边,判断是不是树. 析:水题,判断是不是树,首先是有没有环,这个可以用并查集来判断,然后就是边数等于顶点数减1. 代码如下: #include <bits/stdc++.h&g ...

  7. Codeforces - 1194B - Yet Another Crosses Problem - 水题

    https://codeforc.es/contest/1194/problem/B 好像也没什么思维,就是一个水题,不过蛮有趣的.意思是找缺黑色最少的行列十字.用O(n)的空间预处理掉一维,然后用O ...

  8. Codeforces 1082B Vova and Trophies 模拟,水题,坑 B

    Codeforces 1082B Vova and Trophies https://vjudge.net/problem/CodeForces-1082B 题目: Vova has won nn t ...

  9. CodeForces 686A Free Ice Cream (水题模拟)

    题意:给定初始数量的冰激凌,然后n个操作,如果是“+”,那么数量就会增加,如果是“-”,如果现有的数量大于等于要减的数量,那么就减掉,如果小于, 那么孩子就会离家.问你最后剩下多少冰激凌,和出走的孩子 ...

随机推荐

  1. MBR结构解析与fdisk的bash实现

    一.MBR结构解析 首先我们先介绍一些MBR的基本知识基础,再晾图片分析. MBR主要分为三大块各自是: 1.载入引导程序(446K) 2.分区表(64k) 3.标志结束位(2k) 载入引导程序:内容 ...

  2. 手动安装pip

    apt-get instal pip  成功之后,有根据pip的提示,进行了升级,升级之后,pip就出问题了 为了解决上面问题,手动安装pip,依次执行下面命令 1 2 3 4 5 [root@min ...

  3. JMeter 压力測试使用函数和 CSV 文件參数化 json 数据

            在 http Load Testing 中.json 数据的提交是个让人头疼的问题.本文具体介绍怎样进行 JMeter 的 json 測试提交,以及怎样将其參数化.        St ...

  4. codeforces 553 D Nudist Beach

    题意大概是.给出一个图,保证每一个点至少有一条边以及随意两点间最多一条边.非常显然这个图有众多点集,若我们给每一个点定义一个权值,那每一个点集都有一个最小权值点,如今要求出一个点集,这个点集的最小权值 ...

  5. python(29)- 面向对象练习Ⅲ

    题目: 基于授权定制自己的列表类型,要求定制的自己的__init__方法,   定制自己的append:只能向列表加入字符串类型的值      定制显示列表中间那个值的属性(提示:property)  ...

  6. MySQL 建立外键约束

    http://www.jzxue.com/shujuku/mysql/201109/06-8742.html MySQL 建立外键约束的语法太晦涩难懂了, 不得不记下笔记. 1. 在建表时建立外键 C ...

  7. c语言知识点总结-------静态区、堆、栈、常量区等

    在C语言中地址占4个字节 1.编程语言发展 低级语言----->高级语言 机器语言 ---> 汇编---->高级语言(C语言.C++.JAVA等) 机器语言 :0101 0010 1 ...

  8. linux find prune排除某目录或文件

    http://blog.csdn.net/ysdaniel/article/details/7995681 查找cache目录下不是html的文件 find ./cache ! -name '*.ht ...

  9. 用redis实现跨服务器session(转)

    这个月我们新开发了一个项目,由于使用到了4台机器做web,使用dns做负载均衡, 上面图上用户通过DNS的调度(一个域名对应多个ip)分别访问到VM2-VM5上,四台机器都访问VM1上的redis,两 ...

  10. kubernetes对象之secrets

    系列目录 Secrets是Kubernetes中一种对象类型,用来保存密码.私钥.口令等敏感信息.与直接将敏感信息嵌入image.pod相比,Secrets更安全.更灵活,用户对敏感信息的控制力更强. ...