Find the maximum sum ( a + b ) for a given input integer N satisfying the given condition | Function to return the maximum sum of a + b satisfying the given condition ; Initialize max_sum ; Consider all possible pairs and check the sum divides product property ; To find the largest factor k ; Check if the product is divisible by the sum ; Storing the maximum sum in the max_sum variable ; Return the max_sum value ; Driver code
function getLargestSum ( N ) { let max_sum = 0 ; for ( let i = 1 ; i * i <= N ; i ++ ) { for ( let j = i + 1 ; j * j <= N ; j ++ ) { let k = parseInt ( N / j , 10 ) ; let a = k * i ; let b = k * j ; if ( a <= N && b <= N && a * b % ( a + b ) == 0 ) max_sum = Math . max ( max_sum , a + b ) ; } } return max_sum ; } let N = 25 ; let max_sum = getLargestSum ( N ) ; document . write ( max_sum + " " ) ;