human
Write me a code to count pairs from an array having GCD equal to the minimum element in the pair and the other steps required given the following:
Count pairs from an array having GCD equal to the minimum element in the pair | Function to count pairs from an array having GCD equal to minimum element of that pair.
Stores the resultant count.
Iterate over the range [ 0 , N - 2 ].
Iterate over the range [ i + 1 , N ].
If arr [ i ] % arr [ j ] is 0 or arr [ j ] % arr [ i ] is 0.
Increment count by 1.
Return the resultant count.
Driver Code"
Solution in Python:
assistant
#Here is code to count pairs from an array having GCD equal to the minimum element in the pair and the other steps required.
 def countPairs ( arr , N ) :
	count = 0
	for i in range ( N - 1 ) :
		for j in range ( i + 1 , N ) :
			if ( arr [ i ] % arr [ j ] == 0 or arr [ j ] % arr [ i ] == 0 ) :
				count += 1
	return count
if __name__ == ' _ _ main _ _ ' :
	arr = [ 2 , 3 , 1 , 2 ]
	N = len ( arr )
	print ( countPairs ( arr , N ) )