FUNCTION isprime(k)
  IMPLICIT NONE
  INTEGER, INTENT (in) :: k
  LOGICAL :: isprime

  INTEGER :: i

  isprime = .TRUE.

  DO i=2,k-1
     IF ( MOD(k,i) == 0 ) THEN
        isprime = .FALSE.
        EXIT
     ENDIF
  ENDDO

END FUNCTION isprime


PROGRAM primes
  IMPLICIT NONE
  INTEGER, PARAMETER :: funit = 76
  INTEGER :: i, cnt, N, number, m

  INTERFACE 
     FUNCTION isprime(k)
       IMPLICIT NONE
       INTEGER, INTENT (in) :: k
       LOGICAL :: isprime
     END FUNCTION isprime
  END INTERFACE

  OPEN (funit, file = "rndint", status = "old", action = "read")
  
  cnt = 0
  READ (funit, *) N

  DO i = 1, N
     READ (funit, *) number

     IF (.NOT. isprime(number)) cnt = cnt + 1
  END DO

  CLOSE (funit)
  PRINT *, "File has ", cnt, "non-prime numbers out of ", N

END PROGRAM primes
