Time taken by two persons to meet on a circular track | Function to return the time when both the persons will meet at the starting point ; Time to cover 1 round by both ; Finding LCM to get the meeting point ; Function to return the time when both the persons will meet for the first time ; Driver Code ; Calling function
function startingPoint ( Length , Speed1 , Speed2 ) { var result1 = 0 , result2 = 0 ; var time1 = Length / Speed1 ; var time2 = Length / Speed2 ; result1 = __gcd ( time1 , time2 ) ; result2 = time1 * time2 / ( result1 ) ; return result2 ; } function __gcd ( a , b ) { if ( b == 0 ) { return a ; } return __gcd ( b , a % b ) ; } function firstTime ( Length , Speed1 , Speed2 ) { var result = 0 ; var relativeSpeed = Math . abs ( Speed1 - Speed2 ) ; result = ( Length / relativeSpeed ) ; return result ; } var L = 30 , S1 = 5 , S2 = 2 ; var first_Time = firstTime ( L , S1 , S2 ) ; var starting_Povar = startingPoint ( L , S1 , S2 ) ; document . write ( " " + first_Time + " " ) ; document . write ( " " + starting_Povar + " " ) ;