Count of pairs in an array such that the highest power of 2 that divides their product is 1 | Function to return the count of valid pairs ; To store the count of odd numbers and the count of even numbers such that 2 is the only even factor of that number ; If current number is odd ; If current number is even and 2 is the only even factor of it ; Calculate total number of valid pairs ; Driver code
def cntPairs ( a , n ) : NEW_LINE INDENT odd = 0 ; even = 0 ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( a [ i ] % 2 == 1 ) : NEW_LINE INDENT odd += 1 ; NEW_LINE DEDENT elif ( ( a [ i ] / 2 ) % 2 == 1 ) : NEW_LINE INDENT even += 1 ; NEW_LINE DEDENT DEDENT ans = odd * even + ( odd * ( odd - 1 ) ) // 2 ; NEW_LINE return ans ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT a = [ 4 , 2 , 7 , 11 , 14 , 15 , 18 ] ; NEW_LINE n = len ( a ) ; NEW_LINE print ( cntPairs ( a , n ) ) ; NEW_LINE DEDENT