IsPrime.Rd
Returns for a vector or matrix of positive integers a logical object of the same dimension(s) containing TRUE
for the elements that are prime and FALSE
otherwise.
IsPrime(x)
Given a vector or a matrix of positive integers returns a vector of the same size
of FALSE
and TRUE
. Use which(IsPrime(1:21))
to get the positions.
logical vector
x <- matrix(1:10, nrow=10, ncol=10, byrow=TRUE)
x * IsPrime(x)
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
#> [1,] 0 2 3 0 5 0 7 0 0 0
#> [2,] 0 2 3 0 5 0 7 0 0 0
#> [3,] 0 2 3 0 5 0 7 0 0 0
#> [4,] 0 2 3 0 5 0 7 0 0 0
#> [5,] 0 2 3 0 5 0 7 0 0 0
#> [6,] 0 2 3 0 5 0 7 0 0 0
#> [7,] 0 2 3 0 5 0 7 0 0 0
#> [8,] 0 2 3 0 5 0 7 0 0 0
#> [9,] 0 2 3 0 5 0 7 0 0 0
#> [10,] 0 2 3 0 5 0 7 0 0 0
# Find first prime number octett:
octett <- c(0, 2, 6, 8, 30, 32, 36, 38) - 19
while (TRUE) {
octett <- octett + 210
if (all(IsPrime(octett))) {
cat(octett, "\n", sep=" ")
break
}
}
#> 1006301 1006303 1006307 1006309 1006331 1006333 1006337 1006339