Maximum possible GCD for a pair of integers with sum N | Java program to find the maximum possible GCD of any pair with sum N ; Function to find the required GCD value ; If i is a factor of N ; Return the largest factor possible ; If N is a prime number ; Driver Code
class GFG { static int maxGCD ( int N ) { for ( int i = 2 ; i * i <= N ; i ++ ) { if ( N % i == 0 ) { return N / i ; } } return 1 ; } public static void main ( String [ ] args ) { int N = 33 ; System . out . println ( " Maximum ▁ Possible ▁ GCD ▁ " + " value ▁ is ▁ : ▁ " + maxGCD ( N ) ) ; } }