Find two numbers with given sum and maximum possible LCM | Java 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
import java . util . * ; class GFG { static void maxLCMWithGivenSum ( int X ) { int A , B ; if ( ( X & 1 ) == 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 ; } } System . out . println ( A + " ▁ " + B ) ; } public static void main ( String [ ] args ) { int X = 30 ; maxLCMWithGivenSum ( X ) ; } }