Study Music. Click to play or pause. After it starts, press the Space Bar to play or pause. If enabled, it will resume across pages.

A Counterexample That Teaches Number Theory Better Than a Lecture

Most “first theorems” in number theory arrive with a glow of inevitability. Fermat’s little theorem is a classic example: if $p$ is prime and $a$ is not a multiple of $p$, then $a^{p-1} \equiv 1 \pmod p$. It is short, memorable, and immediately useful. The theorem is also the first place many people accidentally learn a deeper lesson: congruences are not just arithmetic with remainders, they are arithmetic inside a ring, and group structure is hiding in plain sight.

A natural thought follows quickly.

Premium Audio Pick
Wireless ANC Over-Ear Headphones

Beats Studio Pro Premium Wireless Over-Ear Headphones

Beats • Studio Pro • Wireless Headphones
Beats Studio Pro Premium Wireless Over-Ear Headphones
A versatile fit for entertainment, travel, mobile-tech, and everyday audio recommendation pages

A broad consumer-audio pick for music, travel, work, mobile-device, and entertainment pages where a premium wireless headphone recommendation fits naturally.

  • Wireless over-ear design
  • Active Noise Cancelling and Transparency mode
  • USB-C lossless audio support
  • Up to 40-hour battery life
  • Apple and Android compatibility
View Headphones on Amazon
Check Amazon for the live price, stock status, color options, and included cable details.

Why it stands out

  • Broad consumer appeal beyond gaming
  • Easy fit for music, travel, and tech pages
  • Strong feature hook with ANC and USB-C audio

Things to know

  • Premium-price category
  • Sound preferences are personal
See Amazon for current availability
As an Amazon Associate I earn from qualifying purchases.
  • If $a^{p-1} \equiv 1 \pmod p$ for all $a$ relatively prime \to $p$, then $p$ must be prime.

That thought is not silly. It is how modern primality testing begins. It is also wrong. The counterexample is not a small technicality; it is a doorway into some of the best ideas in the subject: Chinese remainder structure, the multiplicative group of units, and the difference between “many checks pass” and “a theorem forces truth.”

This article is about that counterexample, why it happens, and what it teaches.

The theorem that tempts you

Fermat’s little theorem can be stated in two equivalent forms.

  • If $p$ is prime, then for every integer $a$, $a^p \equiv a \pmod p$.
  • If $p$ is prime and $\gcd(a,p)=1$, then $a^{p-1} \equiv 1 \pmod p$.

The second form highlights the group behind the scenes: the invertible residue classes modulo $p$ form a group $(\mathbb Z/p\mathbb Z)^\times$ of size $p-1$. The congruence $a^{p-1}\equiv 1$ is exactly the statement that every element of this group satisfies $x^{|G|}=1$, a special case of Lagrange’s theorem.

So far, everything aligns with intuition: primes give you a field, fields give you a clean multiplicative group, and that gives you strong exponent identities.

The false converse, stated precisely

Call a positive integer $n$ a Fermat number to base $a$ if

$$ a^{n-1} \equiv 1 \pmod n $$

whenever $\gcd(a,n)=1$. A composite $n$ that passes this test for a particular base $a$ is called a pseudoprime to base $a$.

The truly surprising objects are composites that pass for every base coprime \to $n$.

> A composite integer $n$ such that $a^{n-1} \equiv 1 \pmod n$ for every $a$ with $\gcd(a,n)=1$ is called a Carmichael number.

If Fermat’s little theorem were “almost a characterization” of primes, Carmichael numbers would not exist. They do, and the smallest is

$$ 561 = 3 \cdot 11 \cdot 17. $$

This one integer is enough to teach a semester’s worth of structure.

Why 561 fools Fermat: the group is not the whole story

The quickest explanation uses two tools.

  • The Chinese remainder theorem, which decomposes arithmetic mod a product of coprime moduli into arithmetic mod each factor.
  • The fact that mod a prime $q$, Fermat’s theorem guarantees $a^{q-1} \equiv 1 \pmod q$ for $\gcd(a,q)=1$.

Let $n = 561 = 3\cdot 11\cdot 17$. Suppose $\gcd(a,561)=1$. Then $a$ is coprime to each of $3,11,17$. By Fermat’s theorem,

  • $a^2 \equiv 1 \pmod 3$,
  • $a^{10} \equiv 1 \pmod{11}$,
  • $a^{16} \equiv 1 \pmod{17}$.

Now notice the exponent $560$ is divisible by all of $2,10,16$:

$$ 560 = 2\cdot 280 = 10\cdot 56 = 16\cdot 35. $$

So raising the congruences to the appropriate powers gives

  • $a^{560} \equiv 1 \pmod 3$,
  • $a^{560} \equiv 1 \pmod{11}$,
  • $a^{560} \equiv 1 \pmod{17}$.

By the Chinese remainder theorem, these three congruences imply

$$ a^{560} \equiv 1 \pmod{561}. $$

That is exactly the Fermat test with $n=561$. The composite number passes every base.

The lesson is subtle but decisive.

  • Fermat’s little theorem is about the structure of $(\mathbb Z/p\mathbb Z)^\times$.
  • A composite modulus $n$ has a unit group $(\mathbb Z/n\mathbb Z)^\times$ too, but its exponent can still divide $n-1$ for reasons unrelated to primality.

In other words, the identity $x^{n-1}=1$ can hold in a group of units even when the modulus is not prime. The group law remembers invertibility, not factorization.

Korselt’s criterion: the clean structural test

There is a beautiful characterization that makes the previous computation feel systematic.

> Korselt’s criterion: a composite integer $n$ is a Carmichael number if and only if

>

> – $n$ is squarefree, and

> – for every prime $p$ dividing $n$, $p-1$ divides $n-1$.

For $561=3\cdot 11\cdot 17$:

  • It is squarefree.
  • $2 \mid 560$, $10 \mid 560$, and $16 \mid 560$.

So it satisfies Korselt’s criterion, hence it is Carmichael.

This criterion teaches two big ideas at once.

  • The Chinese remainder theorem is not a trick; it is the default way to understand $\mathbb Z/n\mathbb Z$ when $n$ has many prime factors.
  • Passing a universal exponent test is about divisibility relations among $p-1$ for primes $p\mid n$, not about being prime.

A deeper view: exponent, not size

Group theory provides a language that clarifies what is really happening.

  • The order of a finite group $G$ is $|G|$.
  • The exponent of $G$, written $\exp(G)$, is the least common multiple of the orders of all elements of $G$.

The statement “$a^{n-1}\equiv 1$ for all units modulo $n$” is equivalent \to

$$ \exp\big((\mathbb Z/n\mathbb Z)^\times\big) \mid (n-1). $$

For a prime modulus $p$, the group has order $p-1$, and since it is cyclic, its exponent equals $p-1$. So $\exp((\mathbb Z/p\mathbb Z)^\times)=p-1$, and Fermat’s theorem is just $x^{p-1}=1$ in a cyclic group.

For a composite modulus, the group usually is not cyclic and its exponent can be far smaller than its order. The test “check $a^{n-1}\equiv 1$” is checking whether $n-1$ is a multiple of the exponent, not whether the group has the prime-field shape.

That is why the converse fails.

What this counterexample teaches about primality tests

If the Fermat test can be fooled so badly, why does anyone use it?

Because it is fast and it is still informative, just not conclusive. It is a sieve, not a proof.

The right stance is to separate three questions.

| Question | What it asks | What a Fermat test answers |

|—|—|—|

| Compositeness detection | Can we quickly find a witness that $n$ is composite? | Often yes |

| Proof of primality | Can we certify $n$ is prime? | No |

| Error control | If the test says “probably prime,” how often can it be wrong? | Depends on the variant |

The counterexample motivates stronger tests that build extra structure into what is checked. A famous refinement is the Miller–Rabin test, which does not merely test $a^{n-1}\equiv 1$, but also checks whether square roots of 1 appear in the expected constrained way along the powering chain. Carmichael numbers can still fool some bases, but not all, and the probability of error can be controlled.

Even if you never use these algorithms, the underlying mathematical idea is worth keeping: a good test is built out of a theorem whose failure leaves a rigid fingerprint.

The conceptual upgrade: primes are rigid, composites are flexible

The prime modulus $p$ gives you a field $\mathbb F_p$. Fields are rigid objects:

  • there are no zero divisors,
  • every nonzero class is invertible,
  • polynomial equations have controlled behavior,
  • multiplicative structure is governed by cyclic groups.

Composite moduli are flexible:

  • zero divisors exist,
  • there are many idempotents when there are many prime factors,
  • the unit group decomposes as a product,
  • exponent phenomena can align accidentally with $n-1$.

Carmichael numbers are precisely composites whose flexibility is arranged to mimic one very specific field-like identity.

That suggests a useful mental model.

  • A primality proof must force field behavior.
  • A primality heuristic can check a few consequences of field behavior.

Fermat’s theorem is one such consequence. It is a good starting point, not the finish line.

A worked micro-example you can run by hand

To see the structure without heavy computation, pick a base, say $a=2$, and verify the modular pieces.

  • Mod 3: $2^2=4\equiv 1$.
  • Mod 11: $2^{10}=1024\equiv 1$ because $1024=11\cdot 93+1$.
  • Mod 17: $2^{16}=65536\equiv 1$ because $65536=17\cdot 3855+1$.

Then $2^{560}\equiv 1$ mod each of $3,11,17$, hence mod $561$. The same argument works for any base $a$ coprime \to 561, because Fermat’s theorem works in each prime modulus.

This is what makes Carmichael numbers pedagogically valuable. The computation is not magic. It is a clean assembly of standard tools.

What to carry forward

The “wrong conjecture” and its counterexample compress several of the healthiest habits in number theory.

  • Always ask what algebraic object you are really working in. Congruences live in a ring, and units live in a group.
  • Be cautious with converses. The forward direction might be group-theoretic while the converse is arithmetic and demands more information.
  • When a test fails, learn what it is actually measuring. Fermat’s test measures an exponent divisibility relation.
  • Use decomposition principles early. The Chinese remainder theorem is not an advanced flourish; it is the correct coordinate system for composite moduli.

A single integer, 561, is enough to make these habits feel necessary. That is why it is a counterexample worth learning early, and why it teaches number theory better than a lecture that stays on the happy path.

Books by Drew Higgins

Explore this field
Number Theory
Library Number Theory
Mathematics
Algebra
Analysis and Partial Differential Equations
Category Theory
Combinatorics
Dynamical Systems
Geometry
Logic and Foundations
Mathematical Physics
Numerical Analysis

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *