Number of Distinct Meeting Points on a Circular Road | Returns the GCD of two number . ; Returns the number of distinct meeting points . ; Find the relative speed . ; convert the negative value to positive . ; Driver Code
function gcd ( a , b ) { var c = a % b ; while ( c != 0 ) { a = b ; b = c ; c = a % b ; } return b ; } function numberOfmeet ( a , b ) { var ans ; if ( a > b ) ans = a - b ; else ans = b - a ; if ( a < 0 ) a = a * ( - 1 ) ; if ( b < 0 ) b = b * ( - 1 ) ; return ans / gcd ( a , b ) ; } var a = 1 , b = - 1 ; document . write ( numberOfmeet ( a , b ) ) ;