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 x exists 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
47 3 2 1
output
2
input
31 1 1
output
3

第一行说明输入多少个数第二行n个数求里面有多少组数的和为2的k次方
#include <bits/stdc++.h>
using namespace std;
#define ll long long
map<int,int>M;

int main()
{
    ll n;
    cin >> n;
    ll ans = 0;
    ll a;
    ll Fuc = 1;
    while(n--)
    {
        cin >> a;
        for(int i = 0; i < 32; i++)
        {
            if (Fuc < a)
            {
                Fuc *= 2;
                continue;
            }
            else
            {
                ans += M[Fuc-a];
                Fuc *= 2;
            }
        }
        Fuc = 1;
        M[a]++;
    }
    cout << ans << endl;
}
//小心超时哦

  

cf 702B的更多相关文章

  1. CF 702B Powers of Two(暴力)

    题目链接: 传送门 Devu and Partitioning of the Array time limit per test:3 second     memory limit per test: ...

  2. ORA-00494: enqueue [CF] held for too long (more than 900 seconds) by 'inst 1, osid 5166'

    凌晨收到同事电话,反馈应用程序访问Oracle数据库时报错,当时现场现象确认: 1. 应用程序访问不了数据库,使用SQL Developer测试发现访问不了数据库.报ORA-12570 TNS:pac ...

  3. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  4. cf Round 613

    A.Peter and Snow Blower(计算几何) 给定一个点和一个多边形,求出这个多边形绕这个点旋转一圈后形成的面积.保证这个点不在多边形内. 画个图能明白 这个图形是一个圆环,那么就是这个 ...

  5. ARC下OC对象和CF对象之间的桥接(bridge)

    在开发iOS应用程序时我们有时会用到Core Foundation对象简称CF,例如Core Graphics.Core Text,并且我们可能需要将CF对象和OC对象进行互相转化,我们知道,ARC环 ...

  6. [Recommendation System] 推荐系统之协同过滤(CF)算法详解和实现

    1 集体智慧和协同过滤 1.1 什么是集体智慧(社会计算)? 集体智慧 (Collective Intelligence) 并不是 Web2.0 时代特有的,只是在 Web2.0 时代,大家在 Web ...

  7. CF memsql Start[c]UP 2.0 A

    CF memsql Start[c]UP 2.0 A A. Golden System time limit per test 1 second memory limit per test 256 m ...

  8. CF memsql Start[c]UP 2.0 B

    CF memsql Start[c]UP 2.0 B B. Distributed Join time limit per test 1 second memory limit per test 25 ...

  9. CF #376 (Div. 2) C. dfs

    1.CF #376 (Div. 2)    C. Socks       dfs 2.题意:给袜子上色,使n天左右脚袜子都同样颜色. 3.总结:一开始用链表存图,一直TLE test 6 (1)如果需 ...

随机推荐

  1. c++预编译问题:fatal error C1083: Cannot open precompiled header file: 'Debug/DllTest.pch': No such file or d

    1)单独编译StdAfx.cpp 2)编译所有(即按Ctrl+F7) 这时因为该模块没有包括预编译头文件“stdafx.h”的缘故.VC用一个stdafx.cpp包含头文件stdafx.h,然后在st ...

  2. php hook example

    http://www.thinkphp.cn/code/337.html http://blog.micxp.com/index.php/archives/63/

  3. 桂电在线-转变成bootstrap版3(记录学习bootstrap)

    继续上文 正文菜单 html: <!-- 菜单块 --> <div class="on-light" id="menus"> <s ...

  4. 注册表和ODBC

         注册表使用的是树型体系结构,树中的每个结点称键.每个键也可以包含其他的键或子键.它允许进一步的分支,也即为值,它用来存储有效的数据.在注册表中,注册表用键来组织数据,一个键中的值用它们的名来 ...

  5. 2016022607 - redis配置文件

    在Redis有配置文件(redis.conf)可在Redis的根目录下找到.可以通过Redis的CONFIG命令设置所有Redis的配置. Redis的CONFIG命令的基本语法如下所示: redis ...

  6. Encoding 类别

    Encoding 類別 .NET Framework 4.5   表示字元編碼方式. 繼承階層架構 System.Object   System.Text.Encoding    System.Tex ...

  7. encodeURL() vs encodeRedirectURL()

    当用URL重写方式来管理Session的时候,通过以上两个方法把session ID写到URL中.不同点是:两个方法确定是否需要包含session ID的逻辑不同.在调用HttpServletResp ...

  8. 【技术贴】解决127.0.0.1和http://localhost均被拦截跳转到另一个网页

    很艰难的历程. 今天安装一个OA系统,要用到http://127.0.0.1输入完成之后,可以进入安装界面,but,我输入完了之后,自动跳到了129129垃圾网站,艹,我真TM服了,我把本地连接网线都 ...

  9. ibatis 中isNull, isNotNull与isEmpty, isNotEmpty区别

    在iBATIS中isNull用于判断参数是否为Null,isNotNull相反 isEmpty判断参数是否为Null或者空,满足其中一个条件则其true isNotEmpty相反,当参数既不为Null ...

  10. mysql 字段存储类型

    摘自:http://zuo.ai.xiao.blog.163.com/blog/static/6079155320121293750732/ 1.数字类型                        ...