Find the maximum GCD possible for some pair in a given range [ L , R ] | Function to calculate GCD ; Function to calculate maximum GCD in a range ; Variable to store the answer ; If Z has two multiples in [ L , R ] ; Update ans ; Return the value ; Input ; Function Call
def GCD ( a , b ) : NEW_LINE INDENT if ( b == 0 ) : NEW_LINE INDENT return a NEW_LINE DEDENT return GCD ( b , a % b ) NEW_LINE DEDENT def maxGCDInRange ( L , R ) : NEW_LINE INDENT ans = 1 NEW_LINE for Z in range ( R , 1 , - 1 ) : NEW_LINE INDENT if ( ( ( R // Z ) - ( L - 1 ) // Z ) > 1 ) : NEW_LINE INDENT ans = Z NEW_LINE break NEW_LINE DEDENT DEDENT return ans NEW_LINE DEDENT L = 102 NEW_LINE R = 139 NEW_LINE print ( maxGCDInRange ( L , R ) ) NEW_LINE