Find two numbers with the given LCM and minimum possible difference | Python3 implementation of the approach ; Function to return the LCM of a and b ; Function to find and print the two numbers ; To find the factors ; To check if i is a factor of x and the minimum possible number satisfying the given conditions ; Driver code
from math import gcd as __gcd , sqrt , ceil NEW_LINE def lcm ( a , b ) : NEW_LINE INDENT return ( a // __gcd ( a , b ) * b ) NEW_LINE DEDENT def findNums ( x ) : NEW_LINE INDENT ans = 0 NEW_LINE for i in range ( 1 , ceil ( sqrt ( x ) ) ) : NEW_LINE INDENT if ( x % i == 0 and lcm ( i , x // i ) == x ) : NEW_LINE INDENT ans = i NEW_LINE DEDENT DEDENT print ( ans , ( x // ans ) ) NEW_LINE DEDENT x = 12 NEW_LINE findNums ( x ) NEW_LINE