Maximum possible GCD for a pair of integers with product N | C # 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
using System ; class GFG { static int gcd ( int a , int b ) { if ( b == 0 ) return a ; return gcd ( b , a % b ) ; } static int getMaxGcd ( int N ) { int maxGcd = int . MinValue , A , B ; for ( int i = 1 ; i <= Math . Sqrt ( N ) ; i ++ ) { if ( N % i == 0 ) { A = i ; B = N / i ; maxGcd = Math . Max ( maxGcd , gcd ( A , B ) ) ; } } return maxGcd ; } public static void Main ( String [ ] s ) { int N = 18 ; Console . WriteLine ( getMaxGcd ( N ) ) ; } }