Your goal: Select a theorem from its hypotheses and explain when it is unavailable.

Start with the idea and one example. Take a break before the written task if you need it. The questions are original teaching exercises, not official past-paper questions.

Names you may know: Fermat’s little theorem; Euler’s theorem; Euler’s totient function; Wilson’s theorem; Chinese remainder theorem (CRT).

Fermat, Euler, Wilson and Chinese Remainder Theorems: the key idea

Euler’s totient φ(n) counts residues 1≤a≤n that are coprime to n; if n=∏pen=\prod p^{e} then ϕ(n)=n∏(1−1/p)\phi (n)=n\prod (1-1/p). Euler’s theorem says aφ(n)≡1 mod na^{\varphi(n)}\equiv 1 \bmod n when gcd(a,n)=1. Fermat’s little theorem is the prime case: ap−1≡1 mod pa^{p-1}\equiv 1 \bmod p if p∤a, and ap≡aa^{p}\equiv a for every integer a. Wilson’s theorem says (p−1)!≡−1 mod p for prime p; for integers n>1 the congruence also characterises primality. The Chinese remainder theorem gives a unique residue modulo mn solving x≡a mod m and x≡b mod n when gcd(m,n)=1. With non-coprime moduli, compatibility modulo their gcd is necessary and sufficient, with uniqueness modulo their lcm. Use these tools only after checking their hypotheses.

Fermat’s little theorem: statement and meaning

Fermat’s little theorem turns a large power into a manageable remainder. Let p be a prime number and a an integer that is not divisible by p. Then ap−1≡1(modp)a^{p-1}\equiv1\pmod p. The symbol ≡\equiv means that the two numbers have the same remainder on division by p. Equivalently, p divides ap−1−1a^{p-1}-1.

A second form is ap≡a(modp)a^p\equiv a\pmod p for every integer a. If p divides a, both sides have remainder zero. Otherwise multiply the first form by a. Keep the conditions with the formula: the exponent p − 1 form needs a nonzero remainder for the base.

Proof of Fermat’s little theorem using remainders

  1. List the products a,2a,3a,…,(p−1)aa,2a,3a,\ldots,(p-1)a. None has remainder zero modulo p: a prime dividing one of these products would have to divide a or its multiplier, and neither is possible.

  2. No two products have the same remainder. If ia≡ja(modp)ia\equiv ja\pmod p, then p divides a(i−j)a(i-j). Since p does not divide a, it divides i − j. But i and j both lie from 1 to p − 1, so their difference has absolute value less than p. It must be zero.

  3. We have p − 1 different nonzero remainders, so they must be precisely 1,2,…,p−11,2,\ldots,p-1, perhaps in a different order. Multiplying them gives ap−1(p−1)!≡(p−1)!(modp)a^{p-1}(p-1)!\equiv(p-1)!\pmod p.

  4. The factorial (p−1)!(p-1)! shares no prime factor with p, so it has a multiplicative inverse modulo p. Multiply both sides by that inverse to obtain ap−1≡1(modp)a^{p-1}\equiv1\pmod p. This explains why cancellation is valid; cancellation in modular arithmetic always needs justification.

The key idea is that multiplying by a number coprime to the modulus rearranges the available invertible remainders. Revisit reduced residue systems or modular inverses and congruences if either step is unfamiliar.

Example: find the remainder of a large power

Find the remainder when 72227^{222} is divided by 13. The number 13 is prime and does not divide 7, so 712≡1(mod13)7^{12}\equiv1\pmod{13}. Now 222=12⋅18+6222=12\cdot18+6, and therefore 7222≡76(mod13)7^{222}\equiv7^6\pmod{13}.

Compute in small steps: 72≡107^2\equiv10, 74≡102≡97^4\equiv10^2\equiv9, and 76≡9⋅10≡12(mod13)7^6\equiv9\cdot10\equiv12\pmod{13}. The required remainder is 12. Reducing after each multiplication keeps the arithmetic small.

Example: prove divisibility without expanding

Prove that n7−nn^7-n is divisible by 42 for every integer n. Fermat gives divisibility by 7 directly. Modulo 2, an integer and its positive powers have the same parity. Modulo 3, either n has remainder zero, or n2≡1n^2\equiv1, so n6≡1n^6\equiv1 and n7≡nn^7\equiv n. Thus 2, 3 and 7 each divide the expression. As they are pairwise coprime, their product 42 divides it.

Common questions about Fermat’s theorem

Is Fermat’s little theorem the same as Fermat’s last theorem?

No. The little theorem is the modular-arithmetic result proved above. Fermat’s last theorem states that xn+yn=znx^n+y^n=z^n has no solution in positive integers x, y, z when the integer exponent n is greater than 2. This lesson teaches the little theorem used in remainder and divisibility problems; it does not prove the last theorem.

Can I reduce any exponent modulo p − 1?

Only after verifying that p is prime and does not divide the base. For example, 76≡0(mod7)7^6\equiv0\pmod7. Replacing the exponent 6 by zero would instead give 70=17^0=1, an incorrect remainder. Check the base before reducing the exponent.

Does passing a Fermat test prove that a number is prime?

No. The composite number 341=11⋅31341=11\cdot31 satisfies 210=1024=3⋅341+12^{10}=1024=3\cdot341+1, hence 2340≡1(mod341)2^{340}\equiv1\pmod{341}. A failed test can prove compositeness when its conditions are checked; passing one test does not prove primality.

How is Euler’s theorem different?

Euler’s theorem permits a composite modulus m, provided the base is coprime to it. The exponent is the totient φ(m)\varphi(m), the number of invertible residue classes modulo m. For a prime p, φ(p)=p−1\varphi(p)=p-1, so Euler’s theorem gives Fermat’s little theorem.

Further reading: MIT 18.310 notes on elementary algebra and the Chinese remainder theorem, including Fermat’s little theorem. The explanation and practice on this website are original teaching material.

A worked example

Find the remainder of 3¹⁰⁰ modulo 7.

Since 7 is prime and does not divide 3, Fermat gives 3⁶≡1. Write 100=6·16+4. Then 3¹⁰⁰≡3⁴=81≡4 mod 7. Exponent reduction is justified by the coprimality condition.

Your turn: change one thing

Solve x≡2 mod 3 and x≡3 mod 5.

Try this on paper before opening the explanation.

Compare your reasoning

Write x=3k+2. Modulo 5 this gives 3k≡1, so k≡2 since 3·2≡1. Therefore x≡8 mod 15. All x=8+15t work and CRT gives uniqueness modulo 15.

Methods and connections

Euler’s totient function: computing phi

For a prime power pkp^{k}, exclude the pk−1p^{k-1} multiples of p:ϕ(pk)=pk−pk−1p: \phi (p^{k})=p^{k}-p^{k-1}. For 60=2²·3·5, inclusion–exclusion over its prime divisors gives φ(60)=60(1−1/2)(1−1/3)(1−1/5)=16. Only distinct prime factors appear in the product.

Wilson’s theorem: why the congruence works

For prime p, every nonzero class has an inverse. Pair each class with its inverse; each pair multiplies to 1. The self-inverse classes satisfy x²≡1, so p divides (x−1)(x+1), giving x≡±1. For odd p, the unpaired product is −1, proving (p−1)!≡−1. The prime p=2 can be checked directly. The converse follows because a composite n has a proper divisor d with 1<d<n, and d divides both (n−1)! and n; it cannot then divide (n−1)!+1.

Binomial coefficients modulo a prime

For prime p and 0<k<p, the integer C(p,k) is divisible by p. In p!/[k!(p−k)!], the numerator has one factor p and the denominator has none. Thus (a+b)p≡ap+bp mod p(a+b)^{p}\equiv a^{p}+b^{p} \bmod p. For example (x+1)⁵≡x⁵+1 mod 5. This conclusion can fail for composite exponents; (1+1)⁴=16 is not congruent to 1⁴+1⁴=2 modulo 4.

Chinese remainder theorem: compatibility and examples

The pair x≡1 mod 4, x≡3 mod 6 is compatible because both residues are odd. The solutions are x≡9 mod 12: check x=1,5,9 among residues 1 mod 4. In contrast x≡0 mod 4 and x≡1 mod 6 is impossible because the parity requirements conflict. With non-coprime moduli, do not multiply moduli and assume unique residues automatically.

Carmichael’s exponent: an advanced extension

The Carmichael function λ(n) is the least positive exponent L such that aL≡1 mod na^{L}\equiv 1 \bmod n for every a coprime to n; set λ(1)=1 by convention. Euler’s theorem ensures such an exponent exists. For odd prime powers λ(pk)=ϕ(pk)\lambda (p^{k})=\phi (p^{k}). For powers of two, λ(2)=1, λ(4)=2 and λ(2k)=2k−2\lambda (2^{k})=2^{k-2} for k≥3. For coprime prime-power factors, take the lcm of their λ values. Thus λ(15)=lcm(2,4)=4, although φ(15)=8. These general formulas are stated here as advanced tools; verify the small example directly on the eight units modulo 15.

Digit arguments are modular arguments

In base b, b≡1 mod b−1 and b≡−1 mod b+1. Consequently the ordinary digit sum and the alternating digit sum preserve the corresponding residues. Read the base-notation lesson for a full derivation and conversion examples.

Pause and check

A trap to avoid: Reducing an exponent modulo phi without coprimality; Carmichael is an optional later extension.

Practise and adjust the level

Foundation checks the language; Core applies the method; Stretch asks you to choose or justify an idea. These are levels within this lesson. A session selects six of the nine questions; unused questions allow the level to change. Advanced theory still needs written practice.

Interactive practice loads here. You can also use the complete question set below.

Write a complete argument

Prove Euler’s theorem by permuting the reduced residues.

Planning hint

List the assumptions and the exact conclusion. Identify the definition or theorem in this lesson that connects them. Explain why its conditions hold before using it.

Read the full solution after your attempt

Let r₁,…,rφ(n) be reduced residues modulo n and gcd(a,n)=1. Multiplication by a permutes their classes. Thus aφ(n)∏ri≡∏ri mod na^{\varphi(n)}\prod r_{i}\equiv \prod r_{i} \bmod n. The product is coprime to n, so it has a modular inverse and may be cancelled. This yields aφ(n)≡1 mod na^{\varphi(n)}\equiv 1 \bmod n.

My proof notebook

Write on paper, or keep a draft here. Compare your reasoning with the solution only after a real attempt. The checklist is your own review, not an automatic mark.

All nine practice questions

Prefer paper or have JavaScript switched off? The complete question set, hints and solutions are here. Interactive practice uses these same questions in an order chosen from your answers.

1. Euler’s theorem requires which condition on a and n?

Foundation

  1. a<n only
  2. a is prime only
  3. n is even
  4. gcd(a,n)=1
Hint

The proof cancels a product of units.

Answer and reasoning

gcd(a,n)=1. Coprimality is essential to the theorem aφ(n)≡1a^{\varphi(n)}\equiv 1.

2. What does φ(n) count?

Foundation

  1. Residues coprime to n
  2. Prime divisors only
  3. All divisors
  4. All integers below n
Hint

Use the definition of reduced residues.

Answer and reasoning

Residues coprime to n. It counts integers from 1 through n with gcd 1 with n.

3. What is φ(12)?

Core

  1. 6
  2. 8
  3. 12
  4. 4
Hint

Use residues 1,5,7,11.

Answer and reasoning

4. These four and only these four classes are coprime to 12.

4. What is 3¹⁰⁰ modulo 7?

Core

  1. 2
  2. 6
  3. 4
  4. 1
Hint

Reduce the exponent modulo 6.

Answer and reasoning

4. 3¹⁰⁰≡3⁴=81≡4 mod 7.

5. x≡2 mod 3 and x≡3 mod 5 gives which class?

Stretch

  1. x≡8 mod 15
  2. x≡5 mod 15
  3. x≡2 mod 15
  4. x≡3 mod 15
Hint

Check the two remainders.

Answer and reasoning

x≡8 mod 15. 8 leaves 2 modulo 3 and 3 modulo 5; CRT gives the unique class modulo 15.

6. What is 6! modulo 7?

Stretch

  1. 0
  2. 1
  3. 5
  4. 6
Hint

Apply Wilson’s theorem.

Answer and reasoning

6. 6!≡−1≡6 mod 7.

7. Fermat’s congruence ap−1≡1 mod pa^{p-1}\equiv 1 \bmod p requires p to be what?

Foundation

  1. Even, with a even
  2. A divisor of a
  3. Prime, with p not dividing a
  4. Any positive integer
Hint

Check both hypotheses.

Answer and reasoning

Prime, with p not dividing a. The stated form needs a prime modulus and a nonzero residue.

8. Find 2¹⁰ modulo 11.

Core

  1. 1
  2. 0
  3. 2
  4. 10
Hint

Apply Fermat at p=11.

Answer and reasoning

1. Since gcd(2,11)=1, 2¹⁰≡1 mod 11.

9. Why do x≡0 mod 4 and x≡1 mod 6 have no solution?

Stretch

  1. They require x to be both even and odd
  2. 4 and 6 are prime
  3. Their product is too large
  4. All congruences conflict
Hint

Check residues modulo their gcd 2.

Answer and reasoning

They require x to be both even and odd. The required residues are incompatible modulo 2.

Choose your next step

Continue to Number bases and digit problems. If this felt difficult, return to a prerequisite above. Every lesson stays open.

Open my revision list →

Original teaching material · IMOolympiad.com. Send a specific correction through our contact page. Learning progress is optional and stays in this browser.