Wieferich Prime Calculator
Prime
- A Wieferich prime is a prime p with 2^(p - 1) congruent to 1 mod p^2 - the conclusion of Fermat's little theorem, but demanded one power of p higher.
- Here p = 1,093, so p^2 = 1,194,649, and the test is whether 2^1092 leaves remainder 1 modulo 1,194,649.
- Computing the power exactly: 2^1092 mod 1,194,649 = 1, and the Wieferich quotient (2^(p - 1) - 1) / p taken mod p is 0.
- Verdict: the remainder is 1, so 1,093 is a Wieferich prime. Only two base-2 Wieferich primes are known: 1,093 and 3,511.
This Wieferich prime calculator tests a prime p against the defining condition of a Wieferich prime: 2^(p - 1) congruent to 1 mod p^2. Fermat's little theorem guarantees that 2^(p - 1) is congruent to 1 mod p, so the Wieferich condition simply demands one power of p higher. Enter a prime and the calculator reports whether it qualifies. Only two base-2 Wieferich primes are known: 1,093 and 3,511. For 1,093, p^2 = 1,194,649, and 2^1092 mod p^2 is exactly 1. Most primes fail: for 23, 2^22 mod 529 = 392, so 23 is not a Wieferich prime, and its Wieferich quotient mod p is 17.
The calculator follows the standard method for this test: reduce 2^(p - 1) modulo p^2 and check whether the remainder equals 1. That direct modular computation is the accepted way to decide the condition, because it evaluates the exact congruence the definition states rather than an approximation. On this page you can see the formula, the step-by-step workings, worked examples such as 1,093 and 23, and the sources behind the facts. Wieferich primes are named for Arthur Wieferich, who connected them to Fermat's Last Theorem in 1909, which is why a page like this pairs a quick answer with the full arithmetic behind it.
Worked examples
1093 - the first Wieferich prime
(1093)
| Wieferich prime (base 2) | Yes |
| 2^(p - 1) mod p^2 | 1 |
| p^2 | 1,194,649 |
| Wieferich quotient mod p | 0 |
3511 - the second Wieferich prime
(3511)
| Wieferich prime (base 2) | Yes |
| 2^(p - 1) mod p^2 | 1 |
| p^2 | 12,327,121 |
| Wieferich quotient mod p | 0 |
23 leaves remainder 392, so it is not Wieferich
(23)
| Wieferich prime (base 2) | No |
| 2^(p - 1) mod p^2 | 392 |
| p^2 | 529 |
| Wieferich quotient mod p | 17 |
What is a Wieferich prime?
A Wieferich prime is a prime p that satisfies the congruence 2^(p - 1) ≡ 1 (mod p^2). The condition looks almost identical to the one in Fermat's little theorem, which states that 2^(p - 1) ≡ 1 (mod p) for any odd prime p. The difference is the modulus: Fermat's theorem works modulo p, while the Wieferich condition demands the same congruence modulo p^2, one power of p higher. That single extra factor of p makes the property rare. Most primes pass Fermat's test but fail the stricter Wieferich test, because the remainder modulo p^2 is usually some value other than 1.
A useful way to measure how far a prime is from being Wieferich is the Wieferich quotient. When 2^(p - 1) is divided by p^2, the remainder is compared with 1; the quotient captures the size of the gap in a normalized form. A prime whose quotient is zero, in the appropriate sense, meets the Wieferich condition. The known examples are few: only two base-2 Wieferich primes have been found, 1,093 and 3,511. For 1,093, p^2 equals 1,194,649, and 2^1092 mod p^2 is exactly 1, confirming the congruence directly. No third base-2 Wieferich prime is known.
A non-example makes the distinction concrete. Take p = 23. Then p^2 = 529, and 2^22 mod 529 equals 392, not 1. So 23 satisfies Fermat's little theorem modulo 23 but is not a Wieferich prime. Its Wieferich quotient mod p is 17, a nonzero value that records the failure. Running a candidate through a Wieferich prime calculator means checking this remainder for each prime and reporting the quotient, so you can see both whether the congruence holds and how far off a near-miss is.
The name comes from Arthur Wieferich, who in 1909 connected these primes to Fermat's Last Theorem. His result showed that if a prime exponent in a hypothetical solution had certain divisibility properties tied to this congruence, the equation could be ruled out. That link gave the condition mathematical weight beyond a curiosity about remainders, and the primes carrying his name remain a subject of active computation because only two are known in base 2.
- Definition: a prime p with 2^(p - 1) ≡ 1 (mod p^2).
- Contrast: Fermat's little theorem requires only 2^(p - 1) ≡ 1 (mod p).
- Known base-2 Wieferich primes: 1,093 and 3,511.
- Check for 1,093: p^2 = 1,194,649 and 2^1092 mod p^2 = 1.
- Check for 23: 2^22 mod 529 = 392, so 23 is not Wieferich; its Wieferich quotient mod p is 17.
- Named for Arthur Wieferich, who linked the primes to Fermat's Last Theorem in 1909.
The two known examples
A Wieferich prime is a prime p such that 2^(p - 1) is congruent to 1 modulo p^2 — the same congruence Fermat's little theorem guarantees modulo p alone, but demanded one power of p higher. Only two base-2 Wieferich primes are known: 1,093 and 3,511. A Wieferich prime calculator tests this exact condition, so the clearest way to understand what it does is to walk through those two known examples in full and then look at a prime that fails.
Start with 1,093. Here p^2 = 1,094 squared, which equals 1,194,649. The exponent is p - 1 = 1,092. Computing 2^1,092 modulo 1,194,649 gives exactly 1. That single result is the entire definition: the remainder is 1, so 1,093 is a Wieferich prime. The check is not approximate and does not depend on a pattern in the digits — it is one modular exponentiation compared against the value 1.
The second known example is 3,511. It passes the same test: for p = 3,511, 2^(p - 1) is congruent to 1 modulo p^2. Together with 1,093, it is one of only two base-2 Wieferich primes known, which is why this calculator's output is so sparse — almost every prime you enter will fail.
To see what failure looks like, take the small prime 23. Its square is 529, and the exponent is 22. Computing 2^22 modulo 529 gives 392, not 1, so 23 is not a Wieferich prime. The nonzero remainder is the point: Fermat's little theorem still holds modulo 23, but the stronger condition modulo 529 breaks down. The brief also records that 23's Wieferich quotient modulo p is 17, a further measure of how far the prime sits from passing.
These examples also explain the name. Wieferich primes are named for Arthur Wieferich, who connected them to Fermat's Last Theorem in 1909. Running the two known cases and one failing case side by side shows exactly what a Wieferich prime calculator checks: a single remainder, equal to 1 for 1,093 and 3,511, and equal to 392 for 23.
| Prime p | p^2 | Exponent p - 1 | 2^(p - 1) mod p^2 | Wieferich prime? |
|---|---|---|---|---|
| 1,093 | 1,194,649 | 1,092 | 1 | Yes |
| 3,511 | — | — | 1 | Yes |
| 23 | 529 | 22 | 392 | No |
Why so few are known
The scarcity of base-2 Wieferich primes is not a surprise to number theorists; it is roughly what they expect. For a prime p, the chance that 2^(p - 1) happens to be congruent to 1 modulo p^2, rather than merely modulo p as Fermat's little theorem guarantees, is about 1 in p. Summing that probability over all primes predicts that the count of Wieferich primes up to a bound x should grow like log log x. That is an extraordinarily slow function. Doubling the exponent of the bound barely nudges the predicted count upward, so each new Wieferich prime should be vastly rarer than the last. A Wieferich prime calculator that tests candidates one at a time is therefore searching for a needle in a haystack that gets denser only very gradually.
The known record fits this picture. Only two base-2 Wieferich primes are known: 1,093 and 3,511. For 1,093, p^2 = 1,194,649 and 2^1092 mod p^2 is exactly 1, confirming the defining property at the square of the prime rather than just the prime. The next known example, 3,511, is only about three times larger, yet no further base-2 Wieferich prime has been found beyond it. Under the log log heuristic, the expected number of Wieferich primes in a range that already contains two is small, so long gaps are entirely consistent with the probabilistic model rather than evidence that something is wrong with the definition.
The scale of the searches makes the emptiness beyond 3,511 striking. Distributed computing projects have tested primes across enormous ranges, far beyond anything a hand calculation or a single machine could reach, and still nothing beyond 3,511 has turned up. This is the practical face of the heuristic: the predicted density falls off so sharply that even massive computational effort yields no new examples. A reader using a Wieferich prime calculator should keep this in mind — a run that checks thousands or millions of primes and returns only 1,093 and 3,511 is behaving exactly as expected, not failing.
It also helps to see what a near miss looks like. The prime 23 is not a Wieferich prime: 2^22 mod 529 = 392, not 1, so it fails the square-level test even though Fermat's little theorem guarantees the congruence modulo 23 itself. Its Wieferich quotient mod p is 17, a measure of how far it sits from the Wieferich condition. Such near misses are common; exact hits are not. The definition traces back to Arthur Wieferich, who connected these primes to Fermat's Last Theorem in 1909, and the rarity he encountered has only become more pronounced as searches have grown.
In short, the small known list is a consequence of a probability that shrinks with every prime tested, combined with the sheer size of the numbers involved. The log log expectation explains why two examples appeared early and why a third has resisted enormous distributed efforts. Anyone running a Wieferich prime calculator is watching a search whose expected yield is tiny by design.
Wieferich primes and Fermat
Arthur Wieferich earned his place in number theory in 1909, when he connected a rare property of the prime 2 to Fermat's Last Theorem. That connection is the reason a Wieferich prime calculator exists as a distinct tool rather than just another modular-exponentiation exercise. The definition is simple: a Wieferich prime is a prime p with 2^(p - 1) congruent to 1 mod p^2. Fermat's little theorem already guarantees that 2^(p - 1) is congruent to 1 mod p, so every odd prime passes the test one power of p lower. A Wieferich prime is the rarer case where the congruence still holds after multiplying the modulus by p again — the square divides 2^(p - 1) - 1, not merely p.
Wieferich's 1909 result concerned the first case of Fermat's Last Theorem, the case where the exponent p does not divide any of x, y, or z in x^p + y^p = z^p. He proved that if a counterexample existed in that first case for an odd prime exponent p, then p would have to be a Wieferich prime. In other words, any prime that failed the base-2 Wieferich test was automatically cleared for the first case. That gave mathematicians a way to eliminate exponents in bulk: check the congruence, and if it fails, move on. The remaining candidates — the Wieferich primes themselves — were the only exponents the first case still had to worry about.
The catch is how few of those candidates are known. Only two base-2 Wieferich primes have ever been found: 1,093 and 3,511. The smaller one is easy to state precisely. For p = 1,093, p^2 = 1,194,649, and 2^1092 mod 1,194,649 is exactly 1. That single line is the whole definition satisfied at once — no remainder, no near miss.
Most primes fail, and often by a wide margin. Take 23, the ninth prime. Here p^2 = 529, and 2^22 mod 529 equals 392, not 1, so 23 is not a Wieferich prime. The size of that remainder is not the whole story, though. The Wieferich quotient of 23 — the remainder of 2^22 mod 529 divided by 23 — is 17, which tells you how far 23 sits from the Wieferich condition in a normalized sense. A quotient of 0 would mean the prime qualifies; 17 means it does not, and the nonzero value is what a Wieferich prime calculator reports alongside the raw residue.
Because the known list is so short, the practical work with a Wieferich prime calculator is mostly elimination. You supply a prime, the tool computes 2^(p - 1) mod p^2, and you compare the result to 1. A match makes that prime a genuine Wieferich prime — a discovery, given how few exist. Anything else rules the prime out, which is exactly the screening Wieferich introduced in 1909 for the first case of Fermat's Last Theorem.
FAQs
What is a Wieferich prime?
A Wieferich prime is a prime p such that 2^(p - 1) is congruent to 1 modulo p^2, not just modulo p. Every odd prime satisfies the weaker condition modulo p, so a Wieferich prime is a rare case where the congruence still holds after squaring the modulus. Our calculator checks this condition directly for any prime you enter.
How many Wieferich primes are known?
Only two Wieferich primes are known in base 2: 1,093 and 3,511. That is despite searches to enormous bounds, which makes them extremely rare. No other base-2 Wieferich primes have been found, so the list has stayed at these two values. Our calculator lets you test any prime you choose.
Is 23 a Wieferich prime?
No. For p = 23, the calculator finds that 2^22 mod 529 equals 392, not 1. Since 529 is 23 squared, this means 23 fails the Wieferich condition. It is an ordinary prime for this test, so 23 does not join 1,093 and 3,511 on the known list.
What is the Wieferich quotient?
The Wieferich quotient is the value (2^(p - 1) - 1) / p taken mod p. It equals 0 exactly when p is a Wieferich prime, so it gives a clean single-number test. Our calculator reports this quotient so you can see how close or far a prime is from meeting the condition.
Why do Wieferich primes matter?
Wieferich primes arose in work on Fermat's Last Theorem and remain a test case for conjectures about prime distribution. Their extreme rarity makes them useful for checking ideas about how primes behave. Even though only 1,093 and 3,511 are known in base 2, they still draw interest from number theorists studying such patterns.
Are there Wieferich primes in other bases?
Yes. The definition generalizes to any base a, and small examples exist for many bases, but base 2 is the classic case. In base 2 only 1,093 and 3,511 are known. Other bases give additional examples, which is why the base matters when you test a prime.