Learn R Programming

gmp (version 0.1)

isprimeprob: 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

isprimeprob(n, reps = 10)

Arguments

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

Value

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

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".

References

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

See Also

nextprime

Examples

Run this code
isprimeprob(210)
isprimeprob(71)

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

Run the code above in your browser using DataLab