Maximum possible GCD for a pair of integers with product N | Python3 program to implement the above approach ; Function to return the maximum GCD ; To find all divisors of N ; If i is a factor ; Store the pair of factors ; Store the maximum GCD ; Return the maximum GCD ; Driver Code
import sys NEW_LINE import math NEW_LINE def getMaxGcd ( N ) : NEW_LINE INDENT maxGcd = - sys . maxsize - 1 NEW_LINE for i in range ( 1 , int ( math . sqrt ( N ) ) + 1 ) : NEW_LINE INDENT if ( N % i == 0 ) : NEW_LINE INDENT A = i NEW_LINE B = N // i NEW_LINE maxGcd = max ( maxGcd , math . gcd ( A , B ) ) NEW_LINE DEDENT DEDENT return maxGcd NEW_LINE DEDENT N = 18 NEW_LINE print ( getMaxGcd ( N ) ) NEW_LINE