Count of pairs in Array such that bitwise AND of XOR of pair and X is 0 | Function to find the number of pairs that satisfy the given criteria i . e . , i < j and ( arr [ i ] ^ arr [ j ] ) & X is 0 ; Stores the resultant count of pairs ; Iterate over the range [ 0 , N ) ; Iterate over the range ; Check for the given condition ; Return the resultant count ; Driver Code
def countOfPairs ( arr , N , X ) : NEW_LINE INDENT count = 0 NEW_LINE for i in range ( N - 1 ) : NEW_LINE INDENT for j in range ( i + 1 , N ) : NEW_LINE INDENT if ( ( ( arr [ i ] ^ arr [ j ] ) & X ) == 0 ) : NEW_LINE INDENT count += 1 NEW_LINE DEDENT DEDENT DEDENT return count NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 3 , 2 , 5 , 4 , 6 , 7 ] NEW_LINE X = 6 NEW_LINE N = len ( arr ) NEW_LINE print ( countOfPairs ( arr , N , X ) ) NEW_LINE DEDENT