Largest number that divides x and is co | Recursive function to return gcd of a and b ; Everything divides 0 ; base case ; a is greater ; function to find largest coprime divisor ; Driver Code
function gcd ( a , b ) { if ( a == 0 b == 0 ) return 0 ; if ( a == b ) return a ; if ( a > b ) return gcd ( a - b , b ) ; return gcd ( a , b - a ) ; } function cpFact ( x , y ) { while ( gcd ( x , y ) != 1 ) { x = x / gcd ( x , y ) ; } return x ; } let x = 15 ; let y = 3 ; document . write ( cpFact ( x , y ) + " " ) ; x = 14 ; y = 28 ; document . write ( cpFact ( x , y ) , " " ) ; x = 7 ; y = 3 ; document . write ( cpFact ( x , y ) ) ;