Description Usage Arguments Details Value References Examples
Fermat's primality test is a probabilistic method (there is a chance, albeit very small, that a composite number will be flagged as prime) for identifying prime numbers. The test is based on Fermat's Little Theorem, which states that if p is prime and a_{p-1} is not divisible by p, then:
1 | fermat_prime(n, k = 1000L)
|
n |
integer |
k |
integer, default 1000 |
a^{p-1} \equiv 1 \space (text{mod} \space p)
The test proceeds as follows: Select a value for a at random that is not divisible by p and check if the equality holds. This test is performed k times and if the equality does not hold, the integer p is composite. It is possible the test will falsely identify a composite number as prime.
TRUE if n is probably prime, FALSE otherwise
Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, Clifford Stein (2001). "Section 31.8: Primality testing". Introduction to Algorithms (Second ed.). MIT Press; McGraw-Hill. Weisstein, Eric W. "Fermat's Little Theorem." From MathWorld–A Wolfram Web Resource. http://mathworld.wolfram.com/FermatsLittleTheorem.html Weisstein, Eric W. "Primality Test." From MathWorld–A Wolfram Web Resource. http://mathworld.wolfram.com/PrimalityTest.html
1 2 | fermat_prime(11)
fermat_prime(221)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.