Largest number less than or equal to N / 2 which is coprime to N | 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
function largestCoprime ( 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 ) ; } var n = 50 ; document . write ( largestCoprime ( n ) ) ;