Find two numbers with given sum and maximum possible LCM | C ++ program of the above approach ; Function that print two numbers with the sum X and maximum possible LCM ; variables to store the result ; If X is odd ; If X is even ; If floor ( X / 2 ) is even ; If floor ( X / 2 ) is odd ; Print the result ; Driver Code ; Given Number ; Function call
#include <bits/stdc++.h> NEW_LINE using namespace std ; void maxLCMWithGivenSum ( int X ) { int A , B ; if ( X & 1 ) { A = X / 2 ; B = X / 2 + 1 ; } else { if ( ( X / 2 ) % 2 == 0 ) { A = X / 2 - 1 ; B = X / 2 + 1 ; } else { A = X / 2 - 2 ; B = X / 2 + 2 ; } } cout << A << " ▁ " << B << endl ; } int main ( ) { int X = 30 ; maxLCMWithGivenSum ( X ) ; return 0 ; }