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
function findevenPair ( A , N ) { let count = 0 ; for ( let i = 0 ; i < N ; i ++ ) if ( A [ i ] % 2 != 0 ) count ++ ; let oddCount = parseInt ( ( count * ( count - 1 ) ) / 2 ) ; return parseInt ( ( N * ( N - 1 ) ) / 2 ) - oddCount ; } let a = [ 5 , 1 , 3 , 2 ] ; let n = a . length ; document . write ( findevenPair ( a , n ) ) ;