码迷,mamicode.com
首页 > 其他好文 > 详细

cf 702B

时间:2016-07-30 18:26:51      阅读:186      评论:0      收藏:0      [点我收藏+]

标签:

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
4
7 3 2 1
output
2
input
3
1 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

标签:

原文地址:http://www.cnblogs.com/yakoazz/p/5721331.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!