text: Finding a Non Transitive Co | Function to return gcd of a and b ; function to check for gcd ; a and b are coprime if their gcd is 1. ; Checks if any possible triplet ( a , b , c ) satifying the condition that ( a , b ) is coprime , ( b , c ) is coprime but ( a , c ) isnt ; Generate and check for all possible triplets between L and R ; if we find any such triplets set flag to true ; flag = True indicates that a pair exists between L and R ; Driver Code ; finding possible Triplet between 2 and 10 ; finding possible Triplet between 23 and 46
code: function gcd ( a , b ) { if ( a == 0 ) return b ; return gcd ( b % a , a ) ; } function coprime ( a , b ) { return ( gcd ( a , b ) == 1 ) ; } function possibleTripletInRange ( L , R ) { let flag = false ; let possibleA = 0 , possibleB = 0 , possibleC = 0 ; for ( let a = L ; a <= R ; a ++ ) { for ( let b = a + 1 ; b <= R ; b ++ ) { for ( let c = b + 1 ; c <= R ; c ++ ) { if ( coprime ( a , b ) && coprime ( b , c ) && ! coprime ( a , c ) ) { flag = true ; possibleA = a ; possibleB = b ; possibleC = c ; break ; } } } } if ( flag == true ) { document . write ( " " + possibleA + " " + possibleB + " " + possibleC + " " + " " + " " + L + " " + R + " " ) ; } else { document . write ( " " + " " + L + " " + R + " " ) ; } } let L , R ; L = 2 ; R = 10 ; possibleTripletInRange ( L , R ) ; L = 23 ; R = 46 ; possibleTripletInRange ( L , R ) ;