function is_prime1 ( n ) c*********************************************************************72 c cc is_prime1() determines whether an integer is prime. c c Licensing: c c This code is distributed under the MIT license. c c Modified: c c 30 December 2022 c c Author: c c John Burkardt c c Input: c c integer n: the value to be tested. c c Output: c c logical is_prime1: is true if the value is prime. c implicit none integer i logical is_prime1 integer n if ( n <= 1 ) then is_prime1 = .false. return end if is_prime1 = .true. do i = 2, n - 1 if ( mod ( n, i ) == 0 ) then is_prime1 = .false. return end if end do return end function is_prime2 ( n ) c*********************************************************************72 c cc is_prime2() determines whether an integer is prime. c c Licensing: c c This code is distributed under the MIT license. c c Modified: c c 30 December 2022 c c Author: c c John Burkardt c c Input: c c integer n: the value to be tested. c c Output: c c logical is_prime2: is true if the value is prime. c implicit none integer i logical is_prime2 integer n integer n_sqrt if ( n <= 1 ) then is_prime2 = .false. return end if if ( n == 2 .or. n == 3 ) then is_prime2 = .true. return end if is_prime2 = .true. n_sqrt = int ( sqrt ( real ( n ) ) ) do i = 2, n_sqrt if ( mod ( n, i ) == 0 ) then is_prime2 = .false. return end if end do return end function is_prime3 ( n ) c*********************************************************************72 c cc is_prime3() determines whether an integer is prime. c c Licensing: c c This code is distributed under the MIT license. c c Modified: c c 30 December 2022 c c Author: c c John Burkardt c c Input: c c integer n: the value to be tested. c c Output: c c logical is_prime3: is true if the value is prime. c implicit none integer i integer ihi logical is_prime3 integer n if ( n <= 1 ) then is_prime3 = .false. return end if if ( ( n == 2 ) .or. ( n == 3 ) ) then is_prime3 = .true. return end if if ( ( mod ( n, 2 ) == 0 ) .or. ( mod ( n, 3 ) == 0 ) ) then is_prime3 = .false. return end if ihi = int ( sqrt ( real ( n ) ) ) do i = 5, ihi, 6 if ( ( mod ( n, i ) == 0 ) .or. ( mod ( n, i + 2 ) == 0 ) ) then is_prime3 = .false. return end if end do is_prime3 = .true. return end