Largest proper fraction with sum of numerator and denominator equal to a given number | Javascript program to find the largest fraction a / b such that a + b is equal to given number and a < b . ; Calculate N / 2 ; ; Check if N is odd or even ; If N is odd answer will be ceil ( n / 2 ) - 1 and floor ( n / 2 ) + 1 ; If N is even check if N / 2 i . e a is even or odd ; If N / 2 is even apply the previous formula ; If N / 2 is odd answer will be ceil ( N / 2 ) - 2 and floor ( N / 2 ) + 2 ; Driver code
function solve ( n ) { let a = n / 2 ; if ( n % 2 != 0 ) { document . write ( ( Math . ceil ( a ) - 1 ) + " " + ( Math . floor ( a ) + 1 ) ) ; } else { if ( parseInt ( a , 10 ) % 2 == 0 ) { document . write ( ( Math . ceil ( a ) - 1 ) + " " + ( Math . floor ( a ) + 1 ) ) ; } else { document . write ( ( Math . ceil ( a ) - 2 ) + " " + ( Math . floor ( a ) + 2 ) ) ; } } } let n = 34 ; solve ( n ) ;