Pair with min absolute difference and whose product is N + 1 or N + 2 | Java program for the above approach ; 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 ; Driver Code ; Given Number ; Function Call
import java . util . * ; class GFG { static void closestDivisors ( int n ) { for ( int i = ( int ) Math . sqrt ( n + 2 ) ; i > 0 ; i -- ) { if ( ( n + 1 ) % i == 0 ) { System . out . print ( i + " , ▁ " + ( n + 1 ) / i ) ; break ; } if ( ( n + 2 ) % i == 0 ) { System . out . print ( i + " , ▁ " + ( n + 2 ) / i ) ; break ; } } } public static void main ( String [ ] args ) { int N = 123 ; closestDivisors ( N ) ; } }