Maximum possible GCD for a pair of integers with sum N | C ++ 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
#include <bits/stdc++.h> NEW_LINE using namespace std ; int maxGCD ( int N ) { for ( int i = 2 ; i * i <= N ; i ++ ) { if ( N % i == 0 ) { return N / i ; } } return 1 ; } int main ( ) { int N = 33 ; cout << " Maximum ▁ Possible ▁ GCD ▁ value ▁ is ▁ : ▁ " << maxGCD ( N ) << endl ; return 0 ; }