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: < ? php 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 ) { $ flag = false ; $ possibleA ; $ possibleB ; $ possibleC ; for ( $ a = $ L ; $ a <= $ R ; $ a ++ ) { for ( $ b = $ a + 1 ; $ b <= $ R ; $ b ++ ) { for ( $ 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 ) { echo " ( " , $ possibleA , " , ▁ " , $ possibleB , " , ▁ " , $ possibleC , " ) " , " ▁ is ▁ one ▁ such ▁ possible ▁ triplet ▁ between ▁ " , $ L , " ▁ and ▁ " , $ R , " STRNEWLINE " ; } else { echo " No ▁ Such ▁ Triplet ▁ exists ▁ between ▁ " , $ L , " ▁ and ▁ " , $ R , " STRNEWLINE " ; } } $ L ; $ R ; $ L = 2 ; $ R = 10 ; possibleTripletInRange ( $ L , $ R ) ; $ L = 23 ; $ R = 46 ; possibleTripletInRange ( $ L , $ R ) ; ? >