human
Count of pairs in an Array with same number of set bits | Function to return the count of Pairs.
Get the maximum element.
Array to store count of bits of all elements upto maxm.
Store the set bits for powers of 2.
Compute the set bits for the remaining elements.
Store the frequency of respective counts of set bits.
Driver Code"
Solution in Python:
assistant
#Here is code to count of pairs in an Array with same number of set bits and the other steps required.
 def countPairs ( arr , N ) :
	maxm = max ( arr )
	i = 0
	k = 0
	bitscount = [ 0 for i in range ( maxm + 1 ) ]
	i = 1
	while i <= maxm :
		bitscount [ i ] = 1
		i *= 2
	for i in range ( 1 , maxm + 1 ) :
		if ( bitscount [ i ] == 1 ) :
			k = i
		if ( bitscount [ i ] == 0 ) :
			bitscount [ i ] = ( bitscount [ k ] + bitscount [ i - k ] )
	setbits = dict ( )
	for i in range ( N ) :
		if bitscount [ arr [ i ] ] in setbits :
			setbits [ bitscount [ arr [ i ] ] ] += 1
		else :
			setbits [ bitscount [ arr [ i ] ] ] = 1
	ans = 0
	for it in setbits . values ( ) :
		ans += it * ( it - 1 ) // 2
	return ans
if __name__ == ' _ _ main _ _ ' :
	N = 12
	arr = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 ]
	print ( countPairs ( arr , N ) )