Fact-checked by Grok 2 weeks ago

Fermat pseudoprime

A Fermat pseudoprime to base a is a composite positive n such that a^{n-1} \equiv 1 \pmod{n}, where a and n are coprime, thereby satisfying the conclusion of despite n not being prime. This property makes such numbers significant in probabilistic primality testing, as they can pass the Fermat test—a simple yet unreliable method for identifying primes—leading to false positives when distinguishing primes from composites. The concept originates from , which states that if p is prime and \gcd(a, p) = 1, then a^{p-1} \equiv 1 \pmod{p}; pseudoprimes exploit this by behaving like primes for specific bases. Historically, pseudoprimes to base 2 were first studied by Pierre Frédéric Sarrus in 1819 (termed "Sarrus numbers") and later named "Poulet numbers" by Paul Poulet in 1926 after he compiled extensive lists of them. There are infinitely many Fermat pseudoprimes to any fixed base a \geq 2, and their density is low, with estimates showing fewer than x^{1 - c \frac{\log \log \log x}{\log \log x}} such numbers up to x for some constant c > 0. A special subclass consists of Carmichael numbers, which are absolute Fermat pseudoprimes: composite n satisfying b^{n-1} \equiv 1 \pmod{n} for every base b coprime to n. The smallest Fermat pseudoprime to base 2 is 341 ($11 \times 31), while the smallest is 561 ($3 \times 11 \times 17). To mitigate the risk of pseudoprimes in testing, multiple bases are often used; for example, testing bases 2, 3, 5, and 7 leaves 1770 composites below $25 \times 10^9 that pass all four tests. These numbers also appear in cryptographic applications, where reliable primality tests are essential for security.

Background

Fermat's Little Theorem

states that if p is a and a is an not divisible by p, then a^{p-1} \equiv 1 \pmod{p}. An equivalent formulation is a^p \equiv a \pmod{p} for any a. Pierre de Fermat first stated the theorem in a letter dated October 18, 1640, to Bernard Frénicle de Bessy, amid a discussion on s prompted by Frénicle's inquiry about whether a 20-digit existed. Fermat did not include a proof in the letter, and the first rigorous proof was provided by Leonhard Euler in 1736. A proof of the equivalent form a^p \equiv a \pmod{p} can be obtained using the binomial theorem. For a \geq 1, expand (a + 1)^p = \sum_{k=0}^p \binom{p}{k} a^{p-k}, which simplifies to (a + 1)^p \equiv a^p + 1 \pmod{p} because p divides \binom{p}{k} for $1 \leq k \leq p-1. Rearranging gives (a + 1)^p - (a + 1) \equiv a^p - a \pmod{p}, and by induction on a, the result holds for all positive integers a; it extends to a = 0 and negative a trivially. Alternatively, a group-theoretic proof relies on the multiplicative group of integers modulo p, denoted (\mathbb{Z}/p\mathbb{Z})^*, which has order p-1. By Lagrange's theorem, for any a not divisible by p, the order of a modulo p divides p-1, so a^{p-1} \equiv 1 \pmod{p}. Euler's theorem generalizes Fermat's Little Theorem to composite moduli: if n \geq 2 is a positive integer and \gcd(a, n) = 1, then a^{\phi(n)} \equiv 1 \pmod{n}, where \phi is counting the integers up to n that are relatively prime to n. For prime p, \phi(p) = p-1, so Euler's theorem reduces to . For example, with p = 5 and a = 2, compute $2^{5-1} = 16 \equiv 1 \pmod{5}.

Fermat Primality Test

The is a probabilistic for determining whether an odd integer n > 2 is likely to be prime, based on , which states that if p is prime and \gcd(a, p) = 1, then a^{p-1} \equiv 1 \pmod{p}. The test leverages the contrapositive: if a^{n-1} \not\equiv 1 \pmod{n} for some base a with $1 < a < n and \gcd(a, n) = 1, then n is definitively composite. In the procedure, select a random base a satisfying the conditions, compute a^{n-1} \mod n using fast modular exponentiation, and check if the result equals 1; if it does, n passes the test and is deemed a probable prime, while failure proves compositeness. This process is repeated with multiple independent bases to enhance reliability, as a single base may yield inconclusive results for certain composites. The test's probabilistic nature arises because some composite numbers can pass for specific bases, but the probability of error decreases exponentially with the number of bases tested, often making it sufficiently accurate for practical purposes like . The algorithm's efficiency stems from fast exponentiation via repeated squaring, which requires only O(\log n) modular multiplications, each taking O(\log^2 n) time for large n, resulting in overall polylogarithmic runtime suitable for numbers with hundreds of digits. Historically, the test traces to Fermat's 1640 correspondence, but it gained prominence in the 1970s as computing demands for large-prime generation in cryptography, such as , necessitated fast, heuristic methods over exhaustive trial division. For example, testing n = 341 with base a = 2 yields $2^{340} \equiv 1 \pmod{341}, suggesting primality, yet $341 = 11 \times 31 is composite, illustrating the test's potential for false positives.

Definition and Examples

Formal Definition

A composite integer n > 1 is called a Fermat pseudoprime to b, where $2 \leq b \leq n-1 and \gcd(b, n) = 1, if it satisfies the b^{n-1} \equiv 1 \pmod{n}. This condition mimics the conclusion of for primes but applies to composites, hence the term "pseudoprime." Typically, Fermat pseudoprimes are defined for odd composite n, since even composites greater than 2 fail the test for base 2 and are not usually considered. The notation FSP_b(n) or psp_b(n) is commonly used to denote that n is a Fermat pseudoprime to base b. The condition b^{n-1} \equiv 1 \pmod{n} implies that the multiplicative order of b modulo n, denoted \operatorname{ord}_n(b), divides n-1. By Euler's theorem, \operatorname{ord}_n(b) always divides \phi(n), where \phi is Euler's totient function, but for composite n, \phi(n) < n-1, so the order divides \gcd(n-1, \phi(n)). The number 1 is not considered, as it is neither prime nor composite, and powers of 2 are excluded, being either prime (for 2) or even composites that do not satisfy the condition for the relevant bases.

Initial Examples

The smallest Fermat pseudoprime to base 2 is 341, a composite number factoring as $11 \times 31. It satisfies the condition $2^{340} \equiv 1 \pmod{341}, passing the despite its compositeness. To verify this, compute $2^{340} modulo 341 using the Chinese Remainder Theorem, as $341 = 11 \times 31. Modulo 11, Fermat's Little Theorem gives $2^{10} \equiv 1 \pmod{11}, so $2^{340} = (2^{10})^{34} \equiv 1^{34} \equiv 1 \pmod{11}. Modulo 31, $2^{30} \equiv 1 \pmod{31} and $340 = 11 \times 30 + 10, so $2^{340} \equiv (2^{30})^{11} \times 2^{10} \equiv 1 \times 2^{10} \pmod{31}. Now, $2^{10} = 1024 and $1024 \div 31 = 33 remainder 1 (since $31 \times 33 = 1023), so $2^{340} \equiv 1 \pmod{31}. Thus, $2^{340} \equiv 1 \pmod{341}. Another early example is 561, factoring as $3 \times 11 \times 17, which is a Fermat pseudoprime to base 2 since $2^{560} \equiv 1 \pmod{561}. This number is notable as the smallest , meaning it behaves as a pseudoprime for every base coprime to 561. Fermat pseudoprimes can be base-specific. For instance, 91 = $7 \times 13 is a Fermat pseudoprime to base 3, satisfying $3^{90} \equiv 1 \pmod{91}, but fails for base 2 since $2^{90} \equiv 64 \pmod{91} \not\equiv 1. The first few Fermat pseudoprimes to base 2 are listed below, along with their factorizations:
nPrime factorization
341$11 \times 31
561$3 \times 11 \times 17
645$3 \times 5 \times 43
1105$5 \times 13 \times 17

Properties

Algebraic Properties

A fundamental algebraic property of a Fermat pseudoprime n to base b (with \gcd(b, n) = 1 and n composite) is that n divides b^{n-1} - 1, or equivalently, b^{n-1} \equiv 1 \pmod{n}. This condition mimics for primes but holds for certain composites, highlighting the failure of the converse. The property implies that the Fermat quotient q_b(n) = \frac{b^{n-1} - 1}{n} is an integer. For primes p, the Fermat quotient q_b(p) is always an integer by , and the extension to pseudoprimes underscores their deceptive behavior in primality testing. Properties of Fermat quotients, such as congruences modulo primes, have been studied for cryptographic applications, where pseudoprimes can introduce vulnerabilities. Consider the case where n = pq with distinct primes p and q. Then n is a Fermat pseudoprime to base b (with \gcd(b, n) = 1) if and only if b^{p-1} \equiv 1 \pmod{q} and b^{q-1} \equiv 1 \pmod{p}. This condition arises because b^{n-1} \equiv 1 \pmod{p} reduces to b^{q-1} \equiv 1 \pmod{p} (using modulo p), and similarly modulo q. Thus, the product of two primes that are themselves Fermat pseudoprimes to base b (trivially true by ) yields a composite Fermat pseudoprime to b precisely when these modular exponentiation conditions hold, reflecting shared order properties of b modulo p and q. Fermat pseudoprimes exhibit non-uniqueness in bases: a fixed composite n can satisfy the condition for multiple bases b coprime to n. The number of such bases b (with $1 < b < n) is given by \prod_{p \mid n} \gcd(n-1, p-1), where the product is over distinct prime divisors p of n. For n = pq, this simplifies to \gcd(pq-1, p-1) \cdot \gcd(pq-1, q-1), and the two gcd terms are equal, yielding a perfect square that is typically greater than 1, ensuring multiple bases exist.

Distribution and Density

The distribution of Fermat pseudoprimes to a fixed base b \geq 2 is asymptotically much sparser than that of prime numbers. Let \pi_b(x) denote the number of such pseudoprimes up to x. An upper bound of \pi_b(x) \ll x^{1 - \frac{1}{2} \frac{\log \log \log x}{\log \log x}} holds for sufficiently large x, indicating a subpolynomial growth rate. There are infinitely many Fermat pseudoprimes to any fixed base b > 1. This follows from an explicit construction: for primes p not dividing b(b^2 - 1), the number m = (b^{2p} - 1)/(b^2 - 1) is composite and satisfies b^{m-1} \equiv 1 \pmod{m}, and distinct primes p yield distinct m. A quantitative lower bound for base 2 arises from the existence of Carmichael numbers, which are Fermat pseudoprimes to every coprime base, including 2. Alford, Granville, and Pomerance proved there are at least x^{0.332} Carmichael numbers up to x for sufficiently large x, hence at least as many base-2 Fermat pseudoprimes. Explicit computations confirm the low density. There are 245 base-2 Fermat pseudoprimes below $10^6, 38,975 below $10^{11}, 101,629 below $10^{12}, and 264,239 below $10^{13}. These figures show steady but slow growth, with the proportion among odd composites decreasing: for example, roughly 0.058% of odd composites up to $10^6 (computed as 245 divided by approximately 421,502 such numbers) are base-2 Fermat pseudoprimes. For composite bases b, the asymptotic density remains similarly sparse under fixed b, though the precise count can vary due to differing order conditions in the modulo n. The uniform upper bound applies regardless of whether b is prime or composite.

Constructions and Factorizations

Poulet numbers are composite odd integers that are Fermat pseudoprimes to base 2, meaning they satisfy $2^{n-1} \equiv 1 \pmod{n} despite being composite. Named after the mathematician Paul Poulet, who first systematically tabulated them up to 100 million in , these numbers are products of distinct odd primes and represent the simplest non-trivial constructions of base-2 Fermat pseudoprimes. A classic example is the smallest Poulet number, $341 = 11 \times 31, which satisfies the despite its composite nature. To construct square-free Fermat pseudoprimes to base 2 as products of distinct primes p_1, p_2, \dots, p_k, select primes such that for all i \neq j, $2^{p_i - 1} \equiv 1 \pmod{p_j}. This condition ensures that the multiplicative order of 2 modulo each p_j divides p_i - 1 for i \neq j, implying by the that $2^{n-1} \equiv 1 \pmod{p_j} for every j, where n = p_1 p_2 \cdots p_k. An iterative method, building on smaller pseudoprimes, involves taking a known square-free pseudoprime n_i with exactly k-1 prime factors and multiplying it by a primitive prime factor p_i of $2^{n_i} - 1 such that p_i \nmid n_i; the result n_{i+1} = p_i n_i is then a square-free pseudoprime to base 2 with exactly k prime factors. This approach yields infinitely many such numbers for any fixed number of prime factors k \geq 2. For Fermat pseudoprimes that are not square-free, such as those of the form n = p^k m with k \geq 2 and \gcd(p, m) = 1, additional conditions on the exponents are required. Specifically, since n-1 is coprime to p, the base must satisfy a^{p-1} \equiv 1 \pmod{p^k}, meaning p is a base-a (a rare property), and the order must lift appropriately via properties of the p-adic valuation or expansions. Furthermore, n must satisfy the Fermat condition modulo m. These constraints make non-square-free examples scarce compared to their square-free counterparts. Carmichael numbers provide a special class of square-free Fermat pseudoprimes, as they pass the Fermat test to every base b coprime to n. By Korselt's criterion, a square-free composite n = p_1 p_2 \cdots p_k is Carmichael if and only if p_i - 1 divides n - 1 for each i. Consequently, the Carmichael function \lambda(n) = \operatorname{lcm}(p_1 - 1, \dots, p_k - 1) divides n - 1, ensuring the pseudoprimality condition holds for all suitable bases, including 2 (since Carmichael numbers are odd). A foundational example is the smallest Carmichael number, $561 = 3 \times 11 \times 17, where \lambda(561) = \operatorname{lcm}(2, 10, 16) = 80 divides $560, and each prime factor p satisfies p divides $2^{\lambda(561)} - 1 = 2^{80} - 1 because the order of 2 modulo p divides p-1, which divides \lambda(561).

Specific Instances

Smallest Fermat Pseudoprimes

The smallest Fermat pseudoprime to base 2 is 341 = 11 × 31, discovered in 1819 by Pierre Frédéric Sarrus as a to a naive converse of . This number satisfies $2^{340} \equiv 1 \pmod{341}, despite being composite, and it marked an early recognition of the limitations in using Fermat's test for primality. Subsequent small Fermat pseudoprimes to base 2 include 561 = × 11 × 17 (the smallest , also a pseudoprime to all bases coprime to it), 645 = × 5 × , and 1105 = 5 × × 17. In 1938, Paul Poulet systematically enumerated all odd Fermat pseudoprimes to base 2 up to 100 million, expanding the known list significantly and highlighting their rarity relative to primes. For base 3, the smallest Fermat pseudoprime is 91 = × , which satisfies $3^{90} \equiv 1 \pmod{91}. Additional small examples to base 3 include 119 = × 17 and 247 = × 19. The following lists the first 10 Fermat pseudoprimes to each base b from 2 to 10, including their prime factorizations where available. These sequences are drawn from established enumerations and illustrate the variation in the smallest such composites across bases.
Base bFirst 10 Fermat Pseudoprimes (with prime factors)
2341 (11×31), 561 (3×11×17), 645 (3×5×43), 1105 (5××17), 1387 (19×73), (7××19), 1905 (3×5×127), 2047 (23×89), 2465 (5×17×29), 2701 (37×73)
391 (7×), 121 (11²), 286 (2×11×), 671 (11×), 703 (19×37), 949 (×73), 1105 (5××17), 1541 (23×67), (7××19), (31×)
4 (3×5), 85 (5×17), 91 (7×), 341 (11×31), 435 (3×5×29), 451 (11×41), 561 (3×11×17), 645 (3×5×43), 703 (19×37), 1105 (5××17)
54 (2²), 124 (2²×31), 217 (7×31), 561 (3×11×17), 781 (11×71), 1541 (23×67), (7××19), (31×), 2821 (7××31), 4123 (7×19×31)
635 (5×7), 185 (5×37), 217 (7×31), 301 (7×43), 481 (×37), 1105 (5××17), 1111 (11×101), 1261 (×97), 1333 (31×43), (7××19)
76 (2×3), 25 (5²), 325 (5²×), 561 (3×11×17), 703 (19×37), 817 (19×43), 1105 (5××17), 1825 (5²×73), 2101 (11×191), 2353 (×181)
89 (3²), 21 (3×7), 45 (3²×5), 63 (3²×7), 65 (5×), 105 (3×5×7), 117 (3²×), 133 (7×19), 153 (3²×17), 231 (3×7×11)
94 (2²), 8 (2³), 28 (2²×7), 52 (2²×), 91 (7×), 121 (11²), 205 (5×41), 286 (2×11×), 364 (2²×7×), 511 (7×73)
109 (3²), 33 (3×11), 91 (7×), 99 (3²×11), 259 (7×37), 451 (11×41), 481 (×37), 561 (3×11×17), 657 (3×3×73), 703 (19×37)

Fermat Pseudoprimes to Fixed Bases

Fermat pseudoprimes to a fixed base b are composite numbers n coprime to b satisfying b^{n-1} \equiv 1 \pmod{n}. These sequences are well-studied for small bases, providing insights into the distribution and construction of such composites. For base b=2, the sequence consists of odd composite numbers passing the Fermat test with this base, often termed Poulet numbers. The first 20 terms, drawn from OEIS A001567, are: 341 ($11 \times 31), 561 ($3 \times 11 \times 17), 645 ($3 \times 5 \times 43), 1105 ($5 \times 13 \times 17), 1387 ($19 \times 73), 1729 ($7 \times 13 \times 19), 1905 ($3 \times 5 \times 127), 2047 ($23 \times 89), 2465 ($5 \times 17 \times 29), 2701 ($37 \times 73), 2821 ($7 \times 13 \times 31), 3277 ($29 \times 113), 4033 ($37 \times 109), 4369 ($17 \times 257), 4371 ($3 \times 31 \times 47), 4681 ($31 \times 151), 5461 ($43 \times 127), 6601 ($7 \times 23 \times 41), 7957 ($73 \times 109), 8321 ($53 \times 157). These numbers include Carmichael numbers as a subset, where the condition holds for all bases coprime to n. A key construction pattern for base 2 involves selecting a prime q \equiv 1 \pmod{12} such that $2q-1 is also prime; then n = q(2q-1) is a Fermat pseudoprime to base 2. For example, 2701 (q=37). This method generates infinitely many such pseudoprimes, illustrating how they cluster around products involving primes whose order divides specific exponents related to $2^k - 1. For instance, factors like 31 (dividing $2^5 - 1) appear in early terms. For base b=3, the sequence from OEIS A005935 lists the first 20 terms as: 91 ($7 \times 13), 121 ($11^2), 286 ($2 \times 11 \times 13), 671 ($11 \times 61), 703 ($19 \times 37), 949 ($13 \times 73), 1105 ($5 \times 13 \times 17), 1541 ($23 \times 67), ($7 \times 13 \times 19), 1891 ($31 \times 61), 2465 ($5 \times 17 \times 29), 2665 ($5 \times 13 \times 41), 2701 ($37 \times 73), 2821 ($7 \times 13 \times 31), 3281 ($17 \times 193), 3367 ($7 \times 13 \times 37), 3751 ($11 \times 341), 4961 ($11 \times 451), 5551 ($7 \times 13 \times 61), 6601 ($7 \times 23 \times 41). An analogous construction applies: for prime q > 3 where $2q-1 is prime, n = q(2q-1) yields a pseudoprime to base 3, as in 91 (q=7) and 703 (q=19). Overlaps occur between sequences; for example, 1105, , 2465, 2701, 2821, and 6601 appear in both base-2 and base-3 lists. Notable overlaps extend to multiple bases. The 1729 is a Fermat pseudoprime to bases 2, , 5, and 6 (all coprime to 1729), but not to 7 since \gcd(7, 1729) = 7 \neq 1. As the smallest Carmichael number, it passes the Fermat test for every base coprime to it, highlighting how some composites deceive multiple fixed-base tests. To generate these pseudoprimes up to $10^6, computational methods typically employ brute-force exponentiation: for each odd composite n in the range, compute b^{n-1} \mod n using fast modular (e.g., exponentiation, O(\log(n-1)) multiplications) and check if it equals 1, after verifying \gcd(b,n)=1. This approach identifies all such n efficiently for limits like $10^6, where direct sieving for primality (e.g., trial division up to \sqrt{n}) precedes the exponentiation step. For base 2 below $10^6, there are 245 such pseudoprimes; for base , 148. Advanced sieves exploiting the multiplicative structure (e.g., precomputing orders modulo factors of b^k - 1) can accelerate searches but are less common for small bounds due to the simplicity of direct checks.

Bases for Fixed Composites

For a fixed n, the bases b that make n a Fermat pseudoprime are known as the Fermat liar bases for n, consisting of all integers b such that \gcd(b, n) = 1 and b^{n-1} \equiv 1 \pmod{n}. These bases represent the values for which the fails to detect the compositeness of n. A classic example is n = 341 = 11 \times 31, which has exactly 100 Fermat liar bases out of the 300 possible bases coprime to 341 (i.e., approximately one-third of them). In contrast, for the smaller composite n = 91 = 7 \times 13, there are 35 Fermat liar bases less than 91 out of the 72 coprime bases (roughly half). If n is a —a square-free composite satisfying certain divisibility conditions on its prime factors—then every base b coprime to n is a Fermat liar, maximizing the set to all \phi(n) such bases. This property follows from the applied to the condition that p-1 divides n-1 for each prime p dividing n. The size of the set of Fermat liar bases for a composite n quantifies the "strength" of its pseudoprimality: a larger proportion indicates n is more likely to evade detection by the Fermat test across random bases, with Carmichael numbers representing the extreme case.

Euler–Jacobi Pseudoprimes

An composite integer n is an Euler–Jacobi pseudoprime to base b if \gcd(b, n) = 1 and b^{(n-1)/2} \equiv \left( \frac{b}{n} \right) \pmod{n}, where \left( \frac{b}{n} \right) is the . This condition generalizes Euler's criterion for primes, which states that for an prime p and \gcd(a, p) = 1, a^{(p-1)/2} \equiv \left( \frac{a}{p} \right) \pmod{p} with the . The extends the multiplicatively to any composite modulus, allowing the test to apply beyond primes while preserving the property for prime n. Every Euler–Jacobi pseudoprime to base b is also a Fermat pseudoprime to base b, since the Jacobi symbol equals \pm 1 under the coprimality assumption, and squaring both sides of the congruence yields b^{n-1} \equiv 1 \pmod{n}. However, the converse does not hold: the Fermat test only requires b^{(n-1)/2} \equiv \pm 1 \pmod{n}, whereas the Euler–Jacobi test specifies the exact value matching the Jacobi symbol, providing a stricter criterion that detects more composites. For instance, 341 (= 11 \times 31) is a Fermat pseudoprime to base 2 because $2^{340} \equiv 1 \pmod{341}, implying $2^{170} \equiv \pm 1 \pmod{341} (in fact, \equiv 1), but \left( \frac{2}{341} \right) = -1, so it fails the Euler–Jacobi condition. In contrast, 1729 (= 7 \times 13 \times 19) satisfies both, with $2^{864} \equiv 1 \equiv \left( \frac{2}{1729} \right) \pmod{1729}. The Euler–Jacobi pseudoprime concept draws from Euler's criterion, formulated by Leonhard Euler around 1748 in his work on quadratic residues. introduced the in 1837, enabling its application to composite numbers and forming the basis for this pseudoprime definition, as detailed in modern texts. The term itself emerged in the study of probabilistic primality tests, notably in the Solovay–Strassen algorithm of 1977, which relies on this condition. There are infinitely many Euler–Jacobi pseudoprimes to any fixed b > 1, though their up to x grows more slowly than that of Fermat pseudoprimes, with asymptotic estimates suggesting a of o(x / \log x) or lower. For 2, the first few are 561, 1105, and , and no odd composite is an Euler–Jacobi pseudoprime to more than half of the bases coprime to it.

Strong and Absolute Pseudoprimes

A to a b is a n that passes a more stringent variant of the , specifically designed to reduce the incidence of false positives compared to ordinary Fermat pseudoprimes. To define it formally, write n-1 = 2^s d where d is odd; then n is a strong pseudoprime to b (with $1 < b < n and \gcd(b, n) = 1) if either b^d \equiv 1 \pmod{n} or there exists an r with $0 \leq r < s such that b^{2^r d} \equiv -1 \pmod{n}. This condition ensures that the test witnesses fewer composites while still identifying all primes correctly. The concept originates from efforts to strengthen probabilistic primality testing, providing a that eliminates many Fermat pseudoprimes that fail under partial exponentiation checks. The Miller-Rabin primality test, which relies on the strong pseudoprime condition, was first proposed by Gary L. Miller in 1976 as a deterministic algorithm assuming the generalized Riemann hypothesis, running in polynomial time for numbers up to a certain size. Michael O. Rabin extended this in 1980 to a fully probabilistic version without such assumptions, where repeated trials with random bases b yield a composite witness with high probability (error less than $1/4 per trial). For small n (e.g., below $2^{64}), the test is deterministic using a fixed set of bases, such as 2, 3, 5, 7, 11, 13, and 23, guaranteeing primality or compositeness. An example of a strong pseudoprime is 2047 ($23 \times 89), which passes the test to base 2 since $2^{1023} \equiv 1 \pmod{2047} (with s=1, d=1023), satisfying b^d \equiv 1 \pmod{n}; yet it is composite; this is the smallest such instance to base 2. Strong pseudoprimes are rarer than Fermat pseudoprimes, with their density estimated to be O((\log n)^{1/2}/n) under certain heuristics, making the Miller-Rabin test highly reliable in practice. Absolute pseudoprimes, also known as Carmichael numbers, represent the strongest form of Fermat pseudoprimes, behaving like primes under the Fermat test for all bases coprime to n. A Carmichael number is a square-free composite positive integer n such that for every integer b with \gcd(b, n) = 1, b^{n-1} \equiv 1 \pmod{n}; equivalently, by Korselt's criterion, n has prime factors p_i where each p_i - 1 divides n - 1. These numbers were first described by Robert D. Carmichael in 1910, with the smallest example being 561 ($3 \times 11 \times 17), which satisfies the condition since 2, 10, and 16 all divide 560. All Carmichael numbers are thus Fermat pseudoprimes to every coprime base, but they are absolute in this universal sense, distinguishing them from base-specific cases. Their existence was proven infinite by Alford, Granville, and Pomerance in 1994, with over 100 trillion known up to $10^{21}, though they remain sparse (density O(n^{2/7})). Unlike strong pseudoprimes, which are tied to specific bases and tests like Miller-Rabin, Carmichael numbers pose a fundamental limitation to any Fermat-based method, as they fool it completely for coprime witnesses.

Applications

Limitations in Primality Testing

The , based on , determines whether a number n is probably prime by checking if a^{n-1} \equiv 1 \pmod{n} for randomly chosen bases a coprime to n. However, this test suffers from a critical mode: composite numbers known as Fermat pseudoprimes pass the test for specific bases, leading to false positives where the algorithm incorrectly identifies a composite as probably prime. In particular, if n is a Fermat pseudoprime to base a, the holds despite n being composite, undermining the test's reliability for deterministic primality verification. The probability of error in the Fermat test depends on the choice of base. For a random base b coprime to a composite n that is not a , the chance that b is a "liar" (failing to reveal compositeness) is less than $1/2, as more than half of such bases serve as witnesses to compositeness. Thus, a single trial has an error probability below $1/2, but fixed bases can fail deterministically if n is a pseudoprime to that base, yielding a 100% error rate in those cases. For , which are Fermat pseudoprimes to all coprime bases, the error probability approaches 1 for random coprime b, making the test ineffective against them without additional measures. A notable historical example illustrating these limitations is the number 561, the smallest , discovered by Václav Šimerka in 1885 and later analyzed by R. D. Carmichael in 1910. This square-free composite ($561 = 3 \times 11 \times 17) passes the Fermat test for every base coprime to it, causing misidentifications in early computational implementations of the test, such as those in factoring software relying on single or fixed bases without safeguards. Such incidents underscored the need for caution in applying the test to unverified candidates, as 561 evades detection unless a base sharing a factor with it is chosen— an unlikely occurrence in standard random selections. To address these weaknesses, the Fermat test is typically augmented with trial division to rule out small factors and multiple independent base trials, reducing the overall error probability to less than (1/2)^k after k successful passes for a composite n. In the worst case, numbers like Carmichael pseudoprimes with many liar bases necessitate supplementary deterministic or stronger probabilistic tests to confirm compositeness reliably. These improvements make the test practical for initial screening in large-scale primality determination, though they do not eliminate the risk entirely without further verification.

Role in Cryptography and Number Theory

Fermat pseudoprimes play a critical role in the generation of probable primes for cryptographic protocols such as , where large composite numbers that mimic primes under certain tests must be identified to ensure key security. In key generation, random candidates are tested for primality using probabilistic methods, and Fermat pseudoprimes serve as composites that can pass initial Fermat-based checks, highlighting the need for more robust verification to avoid weak keys. Understanding these pseudoprimes is essential for designing tests that minimize the risk of incorporating composites into , thereby enhancing the overall robustness of systems like . In , the study of Fermat pseudoprimes has contributed to advancements in , which posits that a given not equal to -1 or a is a primitive root modulo infinitely many primes. Research on pseudoprimes has led to generalizations of this conjecture, exploring the density and distribution of bases for which composites behave like primes under , providing insights into the structure of s modulo composites. Additionally, investigations into Fermat pseudoprimes intersect with Carmichael's lambda function, which measures the exponent of the multiplicative group of integers modulo n and is central to characterizing Carmichael numbers—absolute Fermat pseudoprimes to all coprime bases—as these composites satisfy λ(n) dividing n-1, advancing theoretical bounds on pseudoprime existence. Fermat pseudoprimes find applications in factoring algorithms, such as Pollard's rho method, where they serve as challenging test cases to evaluate the algorithm's performance on numbers that resist simple primality distinctions. In for cryptographic purposes, pseudoprimes are used to assess the quality of prime candidates produced by RNGs, ensuring that generated sequences avoid composites that could compromise in key derivation. Post-2000 developments in have emphasized primality checks that sidestep vulnerabilities inherent in the Fermat test, such as susceptibility to pseudoprimes, by favoring deterministic algorithms like AKS for generating primes in hybrid schemes. For instance, implements multiple rounds of the Miller-Rabin test—up to 64 or 128 iterations depending on bit length—to circumvent Fermat pseudoprime pitfalls, achieving false positive rates as low as 2^{-128} and ensuring reliable generation for and Diffie-Hellman parameters.

References

  1. [1]
    Fermat Pseudoprime -- from Wolfram MathWorld
    A Fermat pseudoprime to a base a, written psp(a), is a composite number n such that a^(n-1)=1 (mod n), i.e., it satisfies Fermat's little theorem.Missing: definition | Show results with:definition
  2. [2]
    [PDF] Fermat pseudoprimes - Dartmouth Mathematics
    Apr 10, 2025 · whenever n is prime and a is an integer. If (1) holds with n composite, then we say that n is a base-a Fermat pseudoprime. Since it is compu-.
  3. [3]
    Pseudo-primes, Weak Pseudoprimes, Strong ... - Numericana
    The most studied pseudoprimes are pseudoprimes to base 2, which have been variously called Fermat pseudoprimes, Fermatians, Sarrus numbers (1819) and Poulet ...
  4. [4]
    [PDF] Fermat Pseudoprimes and Carmichael Numbers 1. Introduction
    (a) Definition: A composite integer n which satisfies bn−1 ≡ 1 mod n for all b with gcd (n, b) = 1 is called an Absolute Fermat Pseudoprime or a Carmichael ...
  5. [5]
    Fermat's Little Theorem -- from Wolfram MathWorld
    Fermat's little theorem shows that, if p is prime, there does not exist a base a<p with (a,p)=1 such that a^(p-1)-1 possesses a nonzero residue modulo p.Missing: statement | Show results with:statement
  6. [6]
    Fermat's Little Theorem | SpringerLink
    Jun 6, 2011 · In a letter to Frénicle, dated October 18, 1640, Fermat stated what is now known as Fermat's theorem or Fermat's little theorem (to distinguish ...
  7. [7]
    [PDF] EULER'S THEOREM 1. Introduction Fermat's little ... - Keith Conrad
    It is the relative primality point of view on the right that lets Fermat's little theorem be extended to a general modulus, as Euler discovered. Theorem 1.2 ( ...
  8. [8]
    [PDF] Primality testing: then and now - Dartmouth Mathematics
    Answer: 341 is prime. 5. Page 7. Fermat: If p is prime and p - a, then a p−1. ≡ 1 (mod p). So, we conclude that it is efficient to check Fermat, but the theorem ...Missing: procedure | Show results with:procedure
  9. [9]
    [PDF] Lecture Notes on Primality Testing
    May 8, 2007 · These algorithms date back to the 1970's and caused a surge in the study of applied number theory. A Simple Deterministic Algorithm. Given an ...
  10. [10]
    [PDF] LARGE PRIME NUMBERS 1. Fermat Pseudoprimes Fermat's Little ...
    If bn %n = b where b ∈ {1,...,n − 1} then n is called a Fermat pseudoprime base b. ... But according to the theory, up to 1/4 of the b-values have the property.<|control11|><|separator|>
  11. [11]
    [PDF] integers 24 (2024) pseudoprimes and fermat numbers
    Feb 19, 2024 · 1. Introduction. A pseudoprime to base b, or psp(b), is a composite positive integer n that satisfies. the conclusion of Fermat's little ...
  12. [12]
    [PDF] PSEUDOPRIMES, PERFECT NUMBERS, AND A PROBLEM OF ...
    ... multiplicative order. {N -1)1 d modulo N. A composite Integer N with this property Is a Fermat ^-pseudoprime. (See. [12], p. 117, where Fermat rf-pseudoprimes ...
  13. [13]
    [PDF] ELEMENTARY NUMBER THEORY (1) (a) Compute 2340 mod 341 ...
    2340 mod 341 is 1. 341 is not prime, and 341 = 11 * 31.
  14. [14]
    [PDF] Problem 1. Prove that a ≡ b (mod c) if and only if a and b ... - People
    We have 85 = 26 + 24 + 22 + 20. 220. ≡ 2 (mod 341) ,. 221. ≡ 4 (mod 341) ... Since 4 · 85 = 340, we have. 210 = 28 · 4 ≡ (−85) · 4 = −340 ≡ 1 (mod 341) .<|control11|><|separator|>
  15. [15]
    [PDF] 1 Fermat Pseudoprimes 2 Carmichael numbers
    Such numbers are called Carmichael numbers. The first few. Carmichael numbers are. 561, 1105, 1729,... Nevertheless, the notion of a Fermat pseudoprime is ...
  16. [16]
    [PDF] Math 406 Exam 2 Solutions Justin Wyss-Gallifent 1. Use the CRT to ...
    Show that 91 is a Fermat Pseudoprime to the base 3. Note that 91 is not prime! Solution: Since gcd (3, 91) = 1, Euler's Theorem tells us that 3φ(91) ≡ 1 mod 91.
  17. [17]
    A005935 - OEIS
    Theorem: If q>3 and both numbers q and (2q-1) are primes then n=q*(2q-1) is a pseudoprime to base 3 (ie n is in the sequence).
  18. [18]
    [PDF] Math 324, Fall 2011 Assignment 5 Solutions Exercise 1. (a) Find the ...
    Show that if n is a pseudoprime to the base a then n is a pseudoprime to ... The Fermat quotient qp(a) of a is defined by qp(a) = ap−1 − 1 p . Show ...
  19. [19]
    [PDF] THE USE OF FERMAT QUOTIENTS IN CRYPTOGRAPHY - DalSpace
    The Fermat quotient is based on Fermat's little theorem [7, p. 113]:. Theorem 1. If p is a prime and u an integer with gcd(u, p) = 1, then up−1 ...
  20. [20]
    A proof that there are infinitely many pseudoprimes base a
    Here we prove that is a is any integer greater than one, then there is an infinite number of pseudoprimes with respect to the base a.
  21. [21]
    There are Infinitely Many Carmichael Numbers - jstor
    Until now Duparc's problem [Du] as to whether there are infinitely many numbers that are simultaneously pseudoprime to both bases 2 and 3 was un- solved, but ...
  22. [22]
    The Pseudoprimes up to 1013 - SpringerLink
    About this paper. Cite this paper. Pinch, R.G.E. (2000). The Pseudoprimes up to 1013 . In: Bosma, W. (eds) Algorithmic Number Theory. ANTS 2000. Lecture Notes ...
  23. [23]
    [PDF] Notes on Fermat Pseudoprimes - OEIS
    Since n − 1 is odd, the multiplicative order of a modulo 2α and modulo each qi should also be odd, so a ≡ 1 (mod 2α), aφ(qi)/2 ≡ 1 (mod qi), hence ordn(a) ...
  24. [24]
    [PDF] l%PJ Following Lehmer we shall call an integer n a pseudoprime if ...
    Following Lehmer we shall call an integer n a pseudoprime if 2n=2 (mod S) and n is not a prime. The smallest pseudoprime is 341= 11.31. Recently Sierpin-.Missing: method | Show results with:method
  25. [25]
    [PDF] Carmichael Numbers - Dartmouth Mathematics
    0. is divisible by every prime factor of n and since 1?. is squarefree it follows that o" - a is divisible by n.
  26. [26]
    Prime Curios! 341 - The Prime Pages
    341 is the smallest pseudoprime to base two. In 1819, French mathematician Pierre Frédéric Sarrus observed that 341 divides 2³⁴¹-2.
  27. [27]
    A001567 - OEIS
    An odd composite number 2n + 1 is in the sequence if and only if ... An odd number n greater than 1 is a Fermat pseudoprime to base b if and only if ((n-1)! - ...
  28. [28]
    The Little Book of Big Primes
    Poulet determined, already in 1938, all the (odd) pseudoprimes. (in base 2) up to 108. Carmichael numbers were starred in Poulet's table. In 1975, Swift ...
  29. [29]
    Prime Curios! 91
    Every smaller odd composite is either a familiar square, ends in 5, has a ... 91 is a Fermat pseudoprime. (There are 2 curios for this number that have ...
  30. [30]
    Table of Fermat pseudoprimes - OeisWiki
    Apr 30, 2012 · The following table gives small Fermat pseudoprimes for bases 2 ≤ a ≤ 1 0 0 (form the A-number as 2 0 1 2 8 + a for 1 1 ≤ a ≤ 1 0 0 .) ...
  31. [31]
  32. [32]
    Prime Curios! 1729 - The Prime Pages
    + The smallest number that is a pseudoprime simultaneously to bases 2, 3 and 5. [Pomerance , Selfridge and Wagstaff]. + If you reverse the middle digits of ...
  33. [33]
    Finding Large Pseudoprimes with a Computer - Math Stack Exchange
    Aug 9, 2018 · I'm checking for Fermat Pseudoprimes and I've written a program that works for reasonably small numbers, e.g. ≤106. It just brute-force checks ...Missing: computational generation sieves
  34. [34]
    341 - Number
    Jan 5, 2012 · Overall, 341 is a Fermat pseudoprime for 1/3 of the 300 possible bases relatively prime to it (i.e., a total of 100 possible bases). This ...
  35. [35]
    [PDF] pseudoprimes and fermat numbers - Purdue University
    1. Introduction. A pseudoprime to base b, or psp(b), is a composite positive integer n that satisfies. the conclusion of Fermat's little theorem, that is,
  36. [36]
    Euler-Jacobi Pseudoprime -- from Wolfram MathWorld
    An Euler pseudoprime is pseudoprime to at most 1/2 of all possible bases less than itself. The first few base-2 Euler-Jacobi pseudoprimes are 561, 1105, 1729, ...Missing: definition | Show results with:definition
  37. [37]
    Euler's Criterion | Brilliant Math & Science Wiki
    In number theory, Euler's criterion tells you if a number is a quadratic residue modulo an odd prime or not. It was discovered by Leonhard Euler in 1748.
  38. [38]
    [PDF] The Pseudoprimes to 25 109 - Dartmouth Mathematics
    For large n, the arithmetic labor of an spsp test is practically the same as for a psp or epsp test. Pseudoprimes to base 2. 341. Euler pseudoprimes to base 2.<|control11|><|separator|>
  39. [39]
    [PDF] Riemann's Hypothesis and Tests for
    INTRODUCTION. Two classic computational problems are finding efficient for: (1) testing primality (deciding whether an integer is prime or composite), ...
  40. [40]
    Probabilistic Algorithm for Testing Primality - ScienceDirect.com
    May 10, 1978 · We present a practical probabilistic algorithm for testing large numbers of arbitrary form for primality. The algorithm has the feature that ...
  41. [41]
    Strong Pseudoprime -- from Wolfram MathWorld
    A strong pseudoprime to a base a is an odd composite number n with n-1=d·2^s (for d odd) for which either a^d=1 (mod n) or a^(d·2^r)
  42. [42]
    [PDF] fermat's test - keith conrad
    Therefore the “probability” that n is a prime or a Carmichael number if no Fermat witness is found after t trials is greater than 1 − 1/2t. This heuristic ...
  43. [43]
    [PDF] Notes on Primality Testing And Public Key Cryptography Part 1
    The Lucas test yields a method to check whether certain numbers known as Fermat numbers are prime. These are numbers for which the prime factorization of n ...<|control11|><|separator|>
  44. [44]
    [PDF] Improved Distributed RSA Key Generation Using the Miller-Rabin Test
    The standard approach to RSA key generation is to select random candidates for p and q and test for primality. This is non-trivial in the distributed setting, ...
  45. [45]
    [PDF] Two Mersenne Prime Conjectures - Purdue University
    Fermat's ... primitive root modulo p, and this is the most popular ... [7] S. S. Wagstaff, Jr., Pseudoprimes and a generalization of Artin's conjecture, Acta Arith.
  46. [46]
    [PDF] There are infinitely many Carmichael numbers
    Until now Duparc's problem [Du] as to whether there are infinitely many numbers that are simultaneously pseudoprime to both bases 2 and 3 was un- solved, but ...
  47. [47]
    [PDF] 24.1 Pollard's Rho Method - Brown Math
    If n is composite, then there is a prime factor p <√n, so this algorithm takes on the order of n cycles to find a proper factor. (See further comments below.).
  48. [48]
    [PDF] An Analysis of Primality Testing and Its Use in Cryptographic ...
    ... 1/4. Therefore by repeated testing we are able to reduce the error probability down to a very small margin of error. A Miller-Rabin test requires as input ...<|control11|><|separator|>