Pair with min absolute difference and whose product is N + 1 or N + 2 | Function to print pair ( a , b ) such that a * b = N + 1 or N + 2 ; Loop to iterate over the desired possible values ; Check for condition 1 ; Check for condition 2 ; Given Number ; Function Call
function closestDivisors ( n ) { for ( var i = parseInt ( Math . sqrt ( n + 2 ) ) ; i > 0 ; i -- ) { if ( ( n + 1 ) % i == 0 ) { document . write ( i + " " + parseInt ( ( n + 1 ) / i ) ) ; break ; } if ( ( n + 2 ) % i == 0 ) { document . write ( i + " " + parseInt ( ( n + 2 ) / i ) ) ; break ; } } } N = 123 ; closestDivisors ( N ) ;