#P1688. Powers of Two

Powers of Two

Powers of Two

题面翻译

给一个长度为nn的序列aa

从中选取ai,aja_i,a_j,使ai+aj=2x,(xN,i<j)a_i+a_j=2^x,(x\in N^* ,i<j)

求序列中有多少对这样的数

P.SP.S

样例1:有(1,4),(2,4)(1,4),(2,4)两对数

题目描述

You are given n n integers a1,a2,...,an a_{1},a_{2},...,a_{n} . Find the number of pairs of indexes i,j i,j ( i&lt;j ) that ai+aj a_{i}+a_{j} is a power of 2 2 (i. e. some integer x x exists so that ai+aj=2x a_{i}+a_{j}=2^{x} ).

输入格式

The first line contains the single positive integer n n ( 1<=n<=105 1<=n<=10^{5} ) — the number of integers.

The second line contains n n positive integers a1,a2,...,an a_{1},a_{2},...,a_{n} ( 1<=ai<=109 1<=a_{i}<=10^{9} ).

输出格式

Print the number of pairs of indexes i,j i,j ( i&lt;j ) that ai+aj a_{i}+a_{j} is a power of 2 2 .

样例 #1

样例输入 #1

4
7 3 2 1

样例输出 #1

2

样例 #2

样例输入 #2

3
1 1 1

样例输出 #2

3

提示

In the first example the following pairs of indexes include in answer: (1,4) (1,4) and (2,4) (2,4) .

In the second example all pairs of indexes (i,j) (i,j) (where i&lt;j ) include in answer.