Find the GCD that lies in given range | Return the greatest common divisor of two numbers ; Return the gretest common divisor of a and b which lie in the given range . ; Loop from 1 to sqrt ( GCD ( a , b ) . ; if i divides the GCD ( a , b ) , then find maximum of three numbers res , i and g / i ; Driver Code
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 maxDivisorRange ( a , b , l , h ) : NEW_LINE INDENT g = gcd ( a , b ) ; NEW_LINE res = - 1 ; NEW_LINE i = l ; NEW_LINE while ( i * i <= g and i <= h ) : NEW_LINE INDENT if ( g % i == 0 ) : NEW_LINE INDENT res = max ( res , max ( i , g / i ) ) ; NEW_LINE DEDENT i += 1 ; NEW_LINE DEDENT return int ( res ) ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT a = 3 ; NEW_LINE b = 27 ; NEW_LINE l = 1 ; NEW_LINE h = 5 ; NEW_LINE print ( maxDivisorRange ( a , b , l , h ) ) ; NEW_LINE DEDENT