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 ; Print the resultant number ; Driver Code
def isPrime ( N ) : NEW_LINE INDENT if ( N == 1 ) : NEW_LINE INDENT return False NEW_LINE DEDENT for i in range ( 2 , N + 1 ) : NEW_LINE INDENT if i * i > N : NEW_LINE INDENT break NEW_LINE DEDENT if ( N % i == 0 ) : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT return True NEW_LINE DEDENT def findCoPrime ( L , R ) : NEW_LINE INDENT coPrime , i = 0 , R + 1 NEW_LINE while True : NEW_LINE INDENT if ( isPrime ( i ) ) : NEW_LINE INDENT coPrime = i NEW_LINE break NEW_LINE DEDENT i += 1 NEW_LINE DEDENT return coPrime NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT L , R = 16 , 17 NEW_LINE print ( findCoPrime ( L , R ) ) NEW_LINE DEDENT