Count unordered pairs ( i , j ) such that product of a [ i ] and a [ j ] is power of two | Function to check if x is power of 2 ; First x in the below expression is for the case when x is 0 ; Function to Count unordered pairs ; is a number can be expressed as power of two ; count total number of unordered pairs ; Driver code
function isPowerOfTwo ( x ) { return ( x > 0 && ( ! ( ( x & ( x - 1 ) ) > 0 ) ) ) ; } function Count_pairs ( a , n ) { let count = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( isPowerOfTwo ( a [ i ] ) ) count ++ ; } let ans = ( count * ( count - 1 ) ) / 2 ; document . write ( ans ) ; } let a = [ 2 , 5 , 8 , 16 , 128 ] ; let n = a . length ; Count_pairs ( a , n ) ;