human
Find pair with maximum GCD in an array | function to find GCD of pair with max GCD in the array.
Calculating MAX in array.
Maintaining count array.
Variable to store the multiples of a number.
Iterating from MAX to 1 GCD is always between MAX and 1 The first GCD found will be the highest as we are decrementing the potential GCD.
Iterating from current potential GCD till it is less than MAX.
A multiple found.
Incrementing potential GCD by itself To check i , 2 i , 3 i ... ..
2 multiples found , max GCD found.
Array in which pair with max GCD is to be found.
Size of array"
How can the above be solved in Python?
 ... Write me a code to find pair with maximum GCD in an array and the other steps required?
assistant
#Here is code to find pair with maximum GCD in an array and the other steps required.
 def findMaxGCD ( arr , n ) :
	high = 0
	for i in range ( 0 , n ) :
		high = max ( high , arr [ i ] )
	count = [ 0 ] * ( high + 1 )
	for i in range ( 0 , n ) :
		count [ arr [ i ] ] += 1
	counter = 0
	for i in range ( high , 0 , - 1 ) :
		j = i
		while ( j <= high ) :
			if ( count [ j ] > 0 ) :
				counter += count [ j ]
			j += i
			if ( counter == 2 ) :
				return i
		counter = 0
arr = [ 1 , 2 , 4 , 8 , 8 , 12 ]
n = len ( arr )
print ( findMaxGCD ( arr , n ) )