swh:1:snp:81eadaa089e8253d8469bcef66aa332632c6c669
Tip revision: 7c9cb68ab5f2055c3ac5af364c5c2febceae395b authored by Hans W. Borchers on 03 April 2017, 19:40:41 UTC
version 2.0.4
version 2.0.4
Tip revision: 7c9cb68
isprime.R
###
### ISPRIME.R Prime number property
###
isprime <- function(x) {
if (is.null(x) || length(x) == 0)
stop("Argument 'x' must be a nonempty vector or matrix.")
if (!is.numeric(x) || any(x < 0) || any(x != round(x)))
stop("All entries of 'x' must be nonnegative integers.")
n <- length(x)
X <- x[1:n]
L <- logical(n)
p <- primes(ceiling(sqrt(max(x))))
for (i in 1:n) {
L[i] <- all(X[i] %% p[p < X[i]] != 0) # all(rem(X[k], p[p < X[k]]))
}
L[X == 1 | X == 0] <- FALSE
N <- as.numeric(L)
dim(N) <- dim(x)
return(N)
}