Chapter

Wilson, Fermat and Euler in Problems

A practical module on applying Fermat, Euler, and Wilson to powers, inverses, and factorials.
Log in to track solved progress and bookmarks.

Theory

Key Idea

Fermat, Euler, and Wilson are not isolated facts to memorise; they are tools for turning large powers and factorials into small residues. In olympiad problems, the key is knowing which theorem applies and why the hypotheses hold.

Basic Facts

Fermat's little theorem: if \(p\) is prime and \(p\nmid a\), then \(a^{p-1}\equiv1\pmod p\). In the form \(a^p\equiv a\pmod p\), it holds for all integers \(a\). Euler's theorem: if \(\gcd(a,n)=1\), then \(a^{\varphi(n)}\equiv1\pmod n\). Wilson's theorem: \(p\) is prime if and only if \((p-1)!\equiv-1\pmod p\).

When to Use This Method

Use Fermat for powers modulo a prime. Use Euler for powers modulo a composite modulus when coprimality holds. Use Wilson for factorials modulo a prime, especially when \((p-1)!\), \((p-2)!\), or the product of all nonzero residues appears.

How to Recognise the Method

If the exponent resembles \(p-1\), \(p\), or a multiple of \(p-1\), try Fermat. If the modulus is composite and the base is coprime to it, look for \(\varphi(n)\). If a factorial almost reaches a prime \(p\), try Wilson.

Typical Mistakes

Do not apply Euler's theorem without checking \(\gcd(a,n)=1\). Do not replace \(\varphi(n)\) by \(n-1\) when \(n\) is not prime. In Wilson's theorem, primality of the modulus is essential: for composite \(n\), the congruence usually fails.

Mini-checklist

1. Is the modulus prime or composite? 2. Is the base coprime to the modulus? 3. Which exponent can be reduced: \(p-1\) or \(\varphi(n)\)? 4. Can the factorial be replaced using Wilson? 5. Has the small case \(p=2\) been checked?

Examples

Example 1. Fermat in One Line

This teaches reducing the exponent modulo \(p-1\).

Problem. Find \(2^{2026}\pmod{11}\).

Solution.

Since \(11\) is prime and \(2^{10}\equiv1\pmod{11}\), reduce the exponent: \(2026\equiv6\pmod{10}\). Thus \(2^{2026}\equiv2^6=64\equiv9\pmod{11}\).

Comment. Coprimality is obvious here: \(11\nmid2\).

Example 2. Euler Instead of Fermat

This shows work with a composite modulus.

Problem. Find \(2^{100}\pmod9\).

Solution.

We have \(\varphi(9)=6\) and \(\gcd(2,9)=1\). Hence \(2^6\equiv1\pmod9\). Since \(100\equiv4\pmod6\), we get \(2^{100}\equiv2^4=16\equiv7\pmod9\).

Comment. Euler requires the base and modulus to be coprime.

Example 3. An Inverse Through Fermat

This shows how to find an inverse residue.

Problem. Find the inverse of \(5\) modulo \(17\).

Solution.

By Fermat, \(5^{16}\equiv1\pmod{17}\), so \(5^{15}\) is the inverse of \(5\). But directly, \(5\cdot7=35\equiv1\pmod{17}\). Answer: \(7\).

Comment. The theorem gives existence and a general method, but a small modulus can be computed directly.

Example 4. Wilson for a Full Factorial

First application of Wilson's theorem.

Problem. Find the residue of \(10!\) modulo \(11\).

Solution.

Since \(11\) is prime, Wilson's theorem gives \(10!\equiv-1\equiv10\pmod{11}\).

Comment. A factorial almost up to a prime points immediately to Wilson.

Example 5. An Incomplete Factorial

This teaches removing the last factors from Wilson.

Problem. Find \(8!\pmod{11}\).

Solution.

By Wilson, \(10!\equiv-1\pmod{11}\). But \(10!=10\cdot9\cdot8!\equiv(-1)(-2)8!\equiv2\cdot8!\pmod{11}\). Hence \(2\cdot8!\equiv-1\equiv10\), so \(8!\equiv5\pmod{11}\).

Comment. Incomplete factorials are often recovered from the full one.

Example 6. The Form \(a^p-a\)

This shows the universal form of Fermat.

Problem. Prove that \(p\mid a^p-a\) for every prime \(p\) and every integer \(a\).

Solution.

If \(p\mid a\), the claim is obvious. If \(p\nmid a\), Fermat gives \(a^{p-1}\equiv1\pmod p\). Multiplying by \(a\), we get \(a^p\equiv a\pmod p\).

Comment. This form is convenient when \(a\) may be divisible by \(p\).

Example 7. Wilson and Primality

This shows how Wilson recognises primes.

Problem. Check the congruence \(6!\equiv-1\pmod7\).

Solution.

Since \(7\) is prime, Wilson gives \(6!\equiv-1\pmod7\). Indeed, \(720=7\cdot102+6\), so \(6\equiv-1\pmod7\).

Comment. For a composite modulus, this conclusion is not allowed.

Example 8. A Mixed Problem

This combines Euler and residues.

Problem. Find the last two digits of \(3^{80}\).

Solution.

Work modulo \(100\). Since \(\gcd(3,100)=1\) and \(\varphi(100)=40\), \(3^{40}\equiv1\pmod{100}\). Therefore \(3^{80}\equiv1\pmod{100}\). The last two digits are \(01\).

Comment. For modulus \(100\), Fermat modulo a prime is not enough.

Problems

Problems

#4.1
#4.1

A Power Modulo \(11\)

Remainders Grade 8 Grade 9 Grade 10 ★★☆☆☆

Find \(2^{2026}\pmod{11}\).

Details
Problem: NT-B2-M04-P001
Difficulty: Level 2 of 5
Tag: Remainders
Grade: Grade 8, Grade 9, Grade 10
#4.2
#4.2

A Power Modulo \(9\)

Remainders Grade 8 Grade 9 Grade 10 ★★☆☆☆

Find \(2^{100}\pmod9\).

Details
Problem: NT-B2-M04-P002
Difficulty: Level 2 of 5
Tag: Remainders
Grade: Grade 8, Grade 9, Grade 10
#4.3
#4.3

Inverse Element

Fermat Grade 8 Grade 9 Grade 10 ★★☆☆☆

Find the inverse of \(7\) modulo \(13\).

Details
Problem: NT-B2-M04-P003
Difficulty: Level 2 of 5
Tag: Fermat
Grade: Grade 8, Grade 9, Grade 10
#4.4
#4.4

Full Factorial

Factorials Grade 8 Grade 9 Grade 10 ★★☆☆☆

Find \(10!\pmod{11}\).

Details
Problem: NT-B2-M04-P004
Difficulty: Level 2 of 5
Tag: Factorials
Grade: Grade 8, Grade 9, Grade 10
#4.5
#4.5

Euler Function

Euler Grade 8 Grade 9 Grade 10 ★★☆☆☆

Find \(\varphi(45)\).

Details
Problem: NT-B2-M04-P005
Difficulty: Level 2 of 5
Tag: Euler
Grade: Grade 8, Grade 9, Grade 10
#4.6
#4.6

The Form \(a^p-a\)

Divisibility Grade 8 Grade 9 Grade 10 ★★★☆☆

Prove that for every prime \(p\) and every integer \(a\), \(p\mid a^p-a\).

Details
Problem: NT-B2-M04-P006
Difficulty: Level 3 of 5
Tag: Divisibility
Grade: Grade 8, Grade 9, Grade 10
#4.7
#4.7

Power Remainder

Remainders Grade 8 Grade 9 Grade 10 ★★★☆☆

Find \(7^{100}\pmod{13}\).

Details
Problem: NT-B2-M04-P007
Difficulty: Level 3 of 5
Tag: Remainders
Grade: Grade 8, Grade 9, Grade 10
#4.8
#4.8

Last Two Digits

Remainders Grade 8 Grade 9 Grade 10 ★★★☆☆

Find the last two digits of \(3^{80}\).

Details
Problem: NT-B2-M04-P008
Difficulty: Level 3 of 5
Tag: Remainders
Grade: Grade 8, Grade 9, Grade 10
#4.9
#4.9

Incomplete Factorial

Factorials Grade 8 Grade 9 Grade 10 ★★★☆☆

Find \(8!\pmod{11}\).

Details
Problem: NT-B2-M04-P009
Difficulty: Level 3 of 5
Tag: Factorials
Grade: Grade 8, Grade 9, Grade 10
#4.10
#4.10

The Factorial \((p-2)!\)

Factorials Grade 8 Grade 9 Grade 10 ★★★☆☆

Let \(p\) be an odd prime. Prove that \((p-2)!\equiv1\pmod p\).

Details
Problem: NT-B2-M04-P010
Difficulty: Level 3 of 5
Tag: Factorials
Grade: Grade 8, Grade 9, Grade 10
#4.11
#4.11

The Factorial \((p-3)!\)

Factorials Grade 8 Grade 9 Grade 10 ★★★★☆

Let \(p>3\) be prime. Find \((p-3)!\pmod p\).

Details
Problem: NT-B2-M04-P011
Difficulty: Level 4 of 5
Tag: Factorials
Grade: Grade 8, Grade 9, Grade 10
#4.12
#4.12

Euler or CRT

Euler Grade 8 Grade 9 Grade 10 ★★★★☆

Find the remainder of \(7^{222}\) modulo \(100\).

Details
Problem: NT-B2-M04-P012
Difficulty: Level 4 of 5
Tag: Euler
Grade: Grade 8, Grade 9, Grade 10
#4.13
#4.13

All Bases

Divisibility Grade 8 Grade 9 Grade 10 ★★★★☆

Let \(p\) be prime. Prove that \(p\mid a^{p+1}-a^2\) for every integer \(a\).

Details
Problem: NT-B2-M04-P013
Difficulty: Level 4 of 5
Tag: Divisibility
Grade: Grade 8, Grade 9, Grade 10
#4.14
#4.14

Composite Check

Wilson Grade 8 Grade 9 Grade 10 ★★★★☆

Show that \(8!\not\equiv-1\pmod9\), and explain why this does not contradict Wilson.

Details
Problem: NT-B2-M04-P014
Difficulty: Level 4 of 5
Tag: Wilson
Grade: Grade 8, Grade 9, Grade 10
#4.15
#4.15

Inverse Through a Power

Euler Grade 8 Grade 9 Grade 10 ★★★★☆

Let \(\gcd(a,n)=1\). Prove that \(a^{\varphi(n)-1}\) is the inverse of \(a\) modulo \(n\).

Details
Problem: NT-B2-M04-P015
Difficulty: Level 4 of 5
Tag: Euler
Grade: Grade 8, Grade 9, Grade 10
#4.16
#4.16

No Such Primes

Fermat Grade 8 Grade 9 Grade 10 ★★★★☆

Find all primes \(p\) such that \(p\mid2^{p-1}+1\).

Details
Problem: NT-B2-M04-P016
Difficulty: Level 4 of 5
Tag: Fermat
Grade: Grade 8, Grade 9, Grade 10
#4.17
#4.17

Proof of Wilson

Proof Grade 8 Grade 9 Grade 10 ★★★★★

Prove Wilson's theorem: if \(p\) is prime, then \((p-1)!\equiv-1\pmod p\).

Details
Problem: NT-B2-M04-P017
Difficulty: Level 5 of 5
Tag: Proof
Grade: Grade 8, Grade 9, Grade 10
#4.18
#4.18

Product of Inverse Pairs

Factorials Grade 8 Grade 9 Grade 10 ★★★★★

Let \(p>3\) be prime. Find the product of all \(x\in\{1,\ldots,p-1\}\) such that \(x\not\equiv x^{-1}\pmod p\), modulo \(p\).

Details
Problem: NT-B2-M04-P018
Difficulty: Level 5 of 5
Tag: Factorials
Grade: Grade 8, Grade 9, Grade 10
#4.19
#4.19

Two Theorems in One Remainder

Euler Grade 8 Grade 9 Grade 10 ★★★★★

Find the remainder of \(11^{2026}\) modulo \(72\).

Details
Problem: NT-B2-M04-P019
Difficulty: Level 5 of 5
Tag: Euler
Grade: Grade 8, Grade 9, Grade 10
#4.20
#4.20

Wilson as a Criterion

Wilson Grade 8 Grade 9 Grade 10 ★★★★★

Prove that if \(n>1\) and \((n-1)!\equiv-1\pmod n\), then \(n\) is prime.

Details
Problem: NT-B2-M04-P020
Difficulty: Level 5 of 5
Tag: Wilson
Grade: Grade 8, Grade 9, Grade 10

Ladders

No published ladders were found.
Previous Chapter
Next Chapter