Pair with min absolute difference and whose product is N + 1 or N + 2 | Python3 program for the above approach ; Function to prpair ( 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
from math import sqrt , ceil , floor NEW_LINE def closestDivisors ( n ) : NEW_LINE INDENT for i in range ( ceil ( sqrt ( n + 2 ) ) , - 1 , - 1 ) : NEW_LINE INDENT if ( ( n + 1 ) % i == 0 ) : NEW_LINE INDENT print ( i , " , " , ( n + 1 ) // i ) NEW_LINE break NEW_LINE DEDENT if ( ( n + 2 ) % i == 0 ) : NEW_LINE INDENT print ( i , " , " , ( n + 2 ) // i ) NEW_LINE break NEW_LINE DEDENT DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N = 123 NEW_LINE closestDivisors ( N ) NEW_LINE DEDENT