is_prime3 <- function ( n ) #*****************************************************************************80 # ## is_prime3() reports whether an integer is prime. # # Licensing: # # This code is distributed under the MIT license. # # Modified: # # 29 December 2022 # # Author: # # John Burkardt. # # Input: # # integer n: the value to be tested. # # Output: # # logical value: true if n is a prime. # { if ( n <= 1 ) { return ( FALSE ) } if ( n <= 3 ) { return ( TRUE ) } if ( ( n %% 2 == 0 ) || ( n %% 3 == 0 ) ) { return ( FALSE ) } i <- 5 while ( i * i <= n ) { if ( ( n %% i == 0 ) || ( n %% ( i + 2 ) == 0 ) ) { return ( FALSE ) } i = i + 6 } return ( TRUE ) }