PROGRAM Prime
   IMPLICIT NONE

   INTEGER :: Number
   INTEGER :: Divisor

   READ(*,*) Number

   IF ( Number < 2 ) THEN
      WRITE(*,*) 'Illegal input: ', Number
   ELSE IF ( Number == 2 ) THEN
      WRITE(*,*) Number, ' is a prime.'
   ELSE IF ( MOD(Number, 2 ) == 0 ) THEN
      WRITE(*,*) Number, ' is NOT a prime.'
   ELSE
      Divisor = 3
      DO 
         IF ( (Divisor ** 2 ) > Number .OR. MOD( Number, Divisor) == 0 ) &
               EXIT
         Divisor = Divisor + 2
      END DO
      
      IF ( Divisor ** 2 > Number ) THEN
         WRITE(*,*) Number, ' is a prime'
      ELSE 
         WRITE(*,*) Number, ' is NOT a prime'
      END IF
   END IF

END PROGRAM Prime  
