human
Number of pairs whose product is a power of 2 | Function to count pairs having product equal to a power of 2.
Stores count of array elements which are power of 2.
If array element contains only one set bit.
Increase count of powers of 2.
Count required number of pairs.
Print the required number of pairs.
Driver Code.
Given array.
Size of the array.
Function call"
Solution in Python:
assistant
#Here is code to number of pairs whose product is a power of 2 and the other steps required.
 def countPairs ( arr , N ) :
	countPowerof2 = 0
	for i in range ( N ) :
		if ( bin ( arr [ i ] ) . count ( '1' ) == 1 ) :
			countPowerof2 += 1
	desiredPairs = ( countPowerof2 * ( countPowerof2 - 1 ) ) // 2
	print ( desiredPairs )
if __name__ == ' _ _ main _ _ ' :
	arr = [ 2 , 4 , 7 , 2 ]
	N = len ( arr )
	countPairs ( arr , N )