human
Pair of integers having least GCD among all given pairs having GCD exceeding K | Function to calculate the GCD of two numbers.
Function to print the pair having a gcd value just greater than the given integer.
Initialize variables.
Iterate until low less than equal to high.
Calculate mid.
Reducing the search space.
Print the answer.
Driver Code.
Given array and K.
Function call"
How can the above be solved in Python?
assistant
#Here is code to pair of integers having least GCD among all given pairs having GCD exceeding K and the other steps required.
 def GCD ( a , b ) :
	if ( b == 0 ) :
		return a
	return GCD ( b , a % b )
def GcdPair ( arr , k ) :
	lo = 0
	hi = len ( arr ) - 1
	ans = [ - 1 , 0 ]
	while ( lo <= hi ) :
		mid = lo + ( hi - lo ) // 2
		if ( GCD ( arr [ mid ] [ 0 ] , arr [ mid ] [ 1 ] ) > k ) :
			ans = arr [ mid ]
			hi = mid - 1
		else :
			lo = mid + 1
	if ( len ( ans ) == - 1 ) :
		print ( " - 1" )
	else :
		print ( " ( " , ans [ 0 ] , " , " , ans [ 1 ] , " ) " )
if __name__ == ' _ _ main _ _ ' :
	arr = [ [ 3 , 6 ] , [ 15 , 30 ] , [ 25 , 75 ] , [ 30 , 120 ] ]
	K = 16
	GcdPair ( arr , K )