Find two numbers with the given LCM and minimum possible difference | 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
function lcm ( a , b ) { return ( a / __gcd ( a , b ) * b ) ; } function __gcd ( a , b ) { return b == 0 ? a : __gcd ( b , a % b ) ; } function findNums ( x ) { let ans = - 1 ; for ( let i = 1 ; i <= Math . sqrt ( x ) ; i ++ ) { if ( x % i == 0 && lcm ( i , Math . floor ( x / i ) ) == x ) { ans = i ; } } document . write ( ans + " " + Math . floor ( x / ans ) ) ; } let x = 12 ; findNums ( x ) ;