Largest number less than or equal to N / 2 which is coprime to N | C ++ implementation of the above approach ; Function to find largest integer less than or equal to N / 2 and is coprime with N ; Handle the case for N = 6 ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; long long largestCoprime ( long long N ) { if ( N == 6 ) return 1 ; else if ( N % 4 == 0 ) return ( N / 2 ) - 1 ; else if ( N % 2 == 0 ) return ( N / 2 ) - 2 ; else return ( ( N - 1 ) / 2 ) ; } int main ( ) { long long int n = 50 ; cout << largestCoprime ( n ) << endl ; return 0 ; }