pub fn fermat(num: &BigUint) -> boolExpand description
Performs a probabilistic primality test using Fermat’s little theorem.
Fermat’s little theorem states that if p is a prime number, then for any
integer a such that 1 < a < p - 1, the number a^(p-1) is congruent to 1 modulo p.
This function tests the primality of num using a set of base witnesses (2, 3, 5, 7, 11, 13, 17, 19, 23, 29).
Note that passing this test does not guarantee that num is prime, but failing it
guarantees that num is composite. Thus, this function can produce false positives,
but not false negatives.
§Arguments
num- A reference to aBigUintrepresenting the number to test for primality.
§Returns
trueifnumpasses the Fermat primality test for all witnesses.falseifnumfails the test for any witness, or ifnumis less than or equal to 1.
§Examples
use num_bigint::BigUint;
use large_primes::fermat;
let number = BigUint::parse_bytes(b"97", 10).unwrap();
assert!(fermat(&number));
let non_prime = BigUint::parse_bytes(b"100", 10).unwrap();
assert!(!fermat(&non_prime));