Number which is co | Function to check whether the given number N is prime or not ; Base Case ; If N has more than one factor , then return false ; Otherwise , return true ; Function to find X which is co - prime with the integers from the range [ L , R ] ; Store the resultant number ; Check for prime integers greater than R ; If the current number is prime , then update coPrime and break out of loop ; Prvar the resultant number ; Driver Code
function isPrime ( N ) { if ( N == 1 ) return false ; for ( var i = 2 ; i * i <= N ; i ++ ) { if ( N % i == 0 ) return false ; } return true ; } function findCoPrime ( L , R ) { var coPrime ; for ( var i = R + 1 ; ; i ++ ) { if ( isPrime ( i ) ) { coPrime = i ; break ; } } return coPrime ; } var L = 16 , R = 17 ; document . write ( findCoPrime ( L , R ) ) ;