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
< ? php function isPowerOfTwo ( $ x ) { return ( $ x && ( ! ( $ x & ( $ x - 1 ) ) ) ) ; } function Count_pairs ( $ a , $ n ) { $ count = 0 ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { if ( isPowerOfTwo ( $ a [ $ i ] ) ) $ count ++ ; } $ ans = ( $ count * ( $ count - 1 ) ) / 2 ; echo $ ans , " STRNEWLINE " ; } $ a = array ( 2 , 5 , 8 , 16 , 128 ) ; $ n = sizeof ( $ a ) ; Count_pairs ( $ a , $ n ) ; ? >