Pair with min absolute difference and whose product is N + 1 or N + 2 | C ++ 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
#include <bits/stdc++.h> NEW_LINE using namespace std ; void closestDivisors ( int n ) { for ( int i = sqrt ( n + 2 ) ; i > 0 ; i -- ) { if ( ( n + 1 ) % i == 0 ) { cout << i << " , ▁ " << ( n + 1 ) / i ; break ; } if ( ( n + 2 ) % i == 0 ) { cout << i << " , ▁ " << ( n + 2 ) / i ; break ; } } } int main ( ) { int N = 123 ; closestDivisors ( N ) ; }