Count pairs with Bitwise | Function to count number of pairs with EVEN bitwise AND ; count odd numbers ; count odd pairs ; return number of even pair ; Driver Code
< ? php function findevenPair ( $ A , $ N ) { $ count = 0 ; for ( $ i = 0 ; $ i < $ N ; $ i ++ ) if ( $ A [ $ i ] % 2 != 0 ) $ count ++ ; $ oddCount = $ count * ( $ count - 1 ) / 2 ; return ( $ N * ( $ N - 1 ) / 2 ) - $ oddCount ; } $ a = array ( 5 , 1 , 3 , 2 ) ; $ n = sizeof ( $ a ) ; echo findevenPair ( $ a , $ n ) . " STRNEWLINE " ; ? >