Find two numbers with the given LCM and minimum possible difference | C ++ 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
#include <bits/stdc++.h> NEW_LINE using namespace std ; int lcm ( int a , int b ) { return ( a / __gcd ( a , b ) * b ) ; } void findNums ( int x ) { int ans ; for ( int i = 1 ; i <= sqrt ( x ) ; i ++ ) { if ( x % i == 0 && lcm ( i , x / i ) == x ) { ans = i ; } } cout << ans << " ▁ " << ( x / ans ) ; } int main ( ) { int x = 12 ; findNums ( x ) ; return 0 ; }