isprime {gmp}R Documentation

Determine if number is prime

Description

Determine whether the number is prime or not. 2: number is prime, 1, number is probably prime (without beeing certain), 0 number is composite.

Usage

isprime(n, reps = 40)  

Arguments

n Integer number, to be tested
reps Integer, number of repeats

Details

This function does some trial divisions, then some Miller-Rabin probabilisticprimary tests. reps controls how many such tests are done, 5 to 10 is a resonable number. More will reduce the chances of a composite being returned as "probably prime".

Value

0 Number is not prime
1 Number is probably prime
2 Number is prime

Author(s)

Antoine Lucas

References

Gnu MP Library see http://swox.com/gmp

See Also

nextprime

Examples

isprime(210)
isprime(71)

# All primes numbers from 1 to 100
t <-isprime(1:100)
(1:100)[t>0]


[Package gmp version 0.4-11 Index]