PROGRAM sieve
  IMPLICIT NONE

  INTEGER :: a(2:1000)
  INTEGER :: i, j
  
  DO i = 2, 1000
     a(i) = i
  END DO

  DO i = 2, 1000
     IF (a(i) == 0) CYCLE
     
     DO j = i+1, 1000
        IF (MOD(a(j), a(i)) == 0) a(j) = 0
     END DO
  END DO

  DO i = 2, 1000
     IF (a(i) /= 0) PRINT *, a(i)
  END DO
  
END PROGRAM sieve
