human
Find A and B from list of divisors | Function to print A and B all of whose divisors are present in the given array.
Sort the array.
A is the largest element from the array.
Iterate from the second largest element.
If current element is not a divisor of A then it must be B.
If current element occurs more than once.
Print A and B.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to find A and B from list of divisors and the other steps required.
 def printNumbers ( arr , n ) :
	arr . sort ( )
	A , B = arr [ n - 1 ] , - 1
	for i in range ( n - 2 , - 1 , - 1 ) :
		if A % arr [ i ] != 0 :
			B = arr [ i ]
			break
		if i - 1 >= 0 and arr [ i ] == arr [ i - 1 ] :
			B = arr [ i ]
			break
	print ( " A ▁ = " , A , " , ▁ B ▁ = " , B )
if __name__ == " _ _ main _ _ " :
	arr = [ 1 , 2 , 4 , 8 , 16 , 1 , 2 , 4 ]
	n = len ( arr )
	printNumbers ( arr , n )