Chapter

Fermat, Euler and Power Cycles

The module teaches how to work with large powers modulo an integer: short cycles, Fermat's little theorem, Euler's theorem, order of an element, modular inverses, and first restrictions on prime divisors of power expressions.
Log in to track solved progress and bookmarks.

Theory

Key Idea

Powers modulo a number do not grow forever: residues begin to repeat. The olympiad task is usually not to “compute a huge power”, but to choose the right period: a short cycle, Fermat's little theorem, Euler's theorem, or the order of an element.

First look for a short cycle. If the modulus is prime, check Fermat. If the modulus is composite and the base is coprime to it, use Euler or split the modulus into parts.

Basic Facts

  • If \(p\) is prime and \(p\nmid a\), then \(a^{p-1}\equiv1\pmod p\).
  • For every prime \(p\), \(a^p\equiv a\pmod p\).
  • If \(\gcd(a,m)=1\), then \(a^{\varphi(m)}\equiv1\pmod m\).
  • The order \(\operatorname{ord}_m(a)\) is the least positive \(t\) such that \(a^t\equiv1\pmod m\).
  • If \(a^n\equiv1\pmod m\), then \(\operatorname{ord}_m(a)\mid n\).
  • For the last two digits work modulo \(100\); for the last digit work modulo \(10\).

When to Use This Method

  • You need the residue of a large power.
  • You need to prove divisibility such as \(m\mid a^n-1\) or \(m\mid a^n-a\).
  • The problem contains a prime divisor of an expression with powers.
  • You need a modular inverse \(a^{-1}\pmod p\).
  • The modulus is composite, but the base is coprime to it.

How to Recognise the Method

If the exponent is huge, reduce it modulo a period. If the modulus is a prime \(p\), the period often divides \(p-1\). If the modulus is composite, first check \(\gcd(a,m)=1\); otherwise Euler's theorem is not available.

If a prime \(p\mid a^k-1\) appears, move to the order of \(a\) modulo \(p\). The order divides both \(k\) and \(p-1\), which often strongly restricts \(p\).

Typical Mistakes

  • Applying Fermat's theorem to a composite modulus.
  • Applying Euler's theorem when the base is not coprime to the modulus.
  • Reducing the exponent by the wrong period, for example by \(\varphi(m)\) when a shorter cycle is known.
  • For last-two-digit problems, working only modulo \(10\).
  • Writing \(a^{p-1}\equiv1\pmod p\) without checking \(p\nmid a\).

Mini-Checklist

  • Which modulus is needed: \(10\), \(100\), a prime \(p\), or a composite \(m\)?
  • Is the base coprime to the modulus?
  • Is there a short cycle better than Euler?
  • What is the exponent modulo the period?
  • If a prime divisor is involved, what order appears?
  • Should the modulus be split using CRT?

Examples

Example 1. A Short Cycle

Sometimes the period is visible faster than any big theorem.

Problem. Find the remainder of \(3^{20}\) modulo \(7\).

Solution.

We have \(3^1\equiv3\), \(3^2\equiv2\), \(3^3\equiv6\), \(3^6\equiv1\pmod7\). Since \(20\equiv2\pmod6\), \(3^{20}\equiv3^2\equiv2\pmod7\).

Comment. The period is \(6\), but it was enough to find the return to \(1\).

Example 2. Last Digit

The last digit is the residue modulo \(10\).

Problem. Find the last digit of \(7^{2026}\).

Solution.

The last digits of powers of \(7\) are \(7,9,3,1\), then the cycle repeats. The period is \(4\). Since \(2026\equiv2\pmod4\), the last digit is the second digit of the cycle, namely \(9\).

Comment. No need to compute the power; only the exponent modulo the period matters.

Example 3. Fermat's Little Theorem

For a prime modulus, the exponent \(p-1\) often neutralises the problem.

Problem. Prove that \(11\mid 2^{10}-1\).

Solution.

Since \(11\) is prime and \(11\nmid2\), Fermat's little theorem gives \(2^{10}\equiv1\pmod{11}\). Therefore \(11\mid2^{10}-1\).

Comment. It is important to check that the base is not divisible by \(11\).

Example 4. Reducing the Exponent

Fermat lets us replace a large exponent by its remainder modulo \(p-1\).

Problem. Find the remainder of \(5^{100}\) modulo \(13\).

Solution.

By Fermat, \(5^{12}\equiv1\pmod{13}\). Since \(100\equiv4\pmod{12}\), \(5^{100}\equiv5^4\pmod{13}\). Also \(5^2=25\equiv-1\pmod{13}\), so \(5^4\equiv1\pmod{13}\).

Comment. Sometimes after Fermat a small convenient square remains.

Example 5. Last Two Digits

For the last two digits we work modulo \(100\), not only modulo \(10\).

Problem. Find the last two digits of \(7^{100}\).

Solution.

Since \(\gcd(7,100)=1\), we can look for a cycle. Notice that \(7^2=49\), and \(7^4\equiv49^2=2401\equiv1\pmod{100}\). Hence \(7^{100}=(7^4)^{25}\equiv1\pmod{100}\). The last two digits are \(01\).

Comment. A short cycle is better than Euler's theorem here.

Example 6. When Euler Works

For a composite modulus, coprimality must be checked.

Problem. Find the remainder of \(3^{100}\) modulo \(35\).

Solution.

\(\gcd(3,35)=1\), so Euler's theorem applies. \(\varphi(35)=\varphi(5)\varphi(7)=4\cdot6=24\). Since \(100\equiv4\pmod{24}\), we get \(3^{100}\equiv3^4=81\equiv11\pmod{35}\).

Comment. If the base and modulus were not coprime, this move would be illegal.

Example 7. Order of an Element

The order is the true period of powers returning to \(1\).

Problem. Find the order of \(2\) modulo \(9\).

Solution.

Compute: \(2^1\equiv2\), \(2^2\equiv4\), \(2^3\equiv8\), \(2^4\equiv7\), \(2^5\equiv5\), \(2^6\equiv1\pmod9\). Since \(1\) did not occur earlier, \(\operatorname{ord}_9(2)=6\).

Comment. After this, \(2^n\equiv1\pmod9\) if and only if \(6\mid n\).

Example 8. Modular Inverse via Fermat

Fermat gives inverses modulo a prime.

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

Solution.

By Fermat, \(4^{16}\equiv1\pmod{17}\), so \(4^{15}\) is an inverse of \(4\). But direct computation is shorter: \(4\cdot13=52\equiv1\pmod{17}\). Therefore the inverse is \(13\).

Comment. The theorem explains existence, but a short calculation is often faster.

Problems

Problems

#12.1
#12.1

Cycle of Powers of Two

Modular Arithmetic Grade 8 Grade 9 ★☆☆☆☆

Find the remainder of \(2^{17}\) modulo \(5\).

Details
Problem: NT-B1-M07-P001
Difficulty: Level 1 of 5
Tag: Modular Arithmetic
Grade: Grade 8, Grade 9
#12.2
#12.2

Last Digit of \(3^{25}\)

Last Digit Grade 8 Grade 9 ★☆☆☆☆

Find the last digit of \(3^{25}\).

Details
Problem: NT-B1-M07-P002
Difficulty: Level 1 of 5
Tag: Last Digit
Grade: Grade 8, Grade 9
#12.3
#12.3

A Power of Four

Modular Arithmetic Grade 8 Grade 9 ★☆☆☆☆

Find the remainder of \(4^{12}\) modulo \(7\).

Details
Problem: NT-B1-M07-P003
Difficulty: Level 1 of 5
Tag: Modular Arithmetic
Grade: Grade 8, Grade 9
#12.4
#12.4

Fermat for \(7\)

Divisibility Grade 8 Grade 9 ★☆☆☆☆

Prove that \(7\mid 3^6-1\).

Details
Problem: NT-B1-M07-P004
Difficulty: Level 1 of 5
Tag: Divisibility
Grade: Grade 8, Grade 9
#12.5
#12.5

When Euler Cannot Be Used

Euler Grade 8 Grade 9 ★☆☆☆☆

Explain why Euler's theorem cannot be applied to \(2^{10}\) modulo \(8\), and find the remainder.

Details
Problem: NT-B1-M07-P005
Difficulty: Level 1 of 5
Tag: Euler
Grade: Grade 8, Grade 9
#12.6
#12.6

A Power of Five Modulo \(11\)

Modular Arithmetic Grade 8 Grade 9 ★★☆☆☆

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

Details
Problem: NT-B1-M07-P006
Difficulty: Level 2 of 5
Tag: Modular Arithmetic
Grade: Grade 8, Grade 9
#12.7
#12.7

A Power of Two Modulo \(13\)

Modular Arithmetic Grade 8 Grade 9 ★★☆☆☆

Find the remainder of \(2^{100}\) modulo \(13\).

Details
Problem: NT-B1-M07-P007
Difficulty: Level 2 of 5
Tag: Modular Arithmetic
Grade: Grade 8, Grade 9
#12.8
#12.8

A Power of Seven Modulo \(9\)

Modular Arithmetic Grade 8 Grade 9 ★★☆☆☆

Find the remainder of \(7^{50}\) modulo \(9\).

Details
Problem: NT-B1-M07-P008
Difficulty: Level 2 of 5
Tag: Modular Arithmetic
Grade: Grade 8, Grade 9
#12.9
#12.9

Last Two Digits of \(3^{40}\)

Euler Grade 8 Grade 9 ★★☆☆☆

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

Details
Problem: NT-B1-M07-P009
Difficulty: Level 2 of 5
Tag: Euler
Grade: Grade 8, Grade 9
#12.10
#12.10

A Power of \(-1\)

Modular Arithmetic Grade 8 Grade 9 ★★☆☆☆

Find the remainder of \(11^{2025}\) modulo \(12\).

Details
Problem: NT-B1-M07-P010
Difficulty: Level 2 of 5
Tag: Modular Arithmetic
Grade: Grade 8, Grade 9
#12.11
#12.11

Order of Three

Order Grade 8 Grade 9 ★★☆☆☆

Find the order of \(3\) modulo \(7\).

Details
Problem: NT-B1-M07-P011
Difficulty: Level 2 of 5
Tag: Order
Grade: Grade 8, Grade 9
#12.12
#12.12

When \(3^n\equiv1\)

Linear Congruence Grade 8 Grade 9 ★★☆☆☆

Find all positive \(n\) such that \(3^n\equiv1\pmod7\).

Details
Problem: NT-B1-M07-P012
Difficulty: Level 2 of 5
Tag: Linear Congruence
Grade: Grade 8, Grade 9
#12.13
#12.13

Sum of Two Large Powers

Casework Grade 9 Grade 10 ★★★☆☆

Find the remainder of \(2^{2026}+3^{2026}\) modulo \(5\).

Details
Problem: NT-B1-M07-P013
Difficulty: Level 3 of 5
Tag: Casework
Grade: Grade 9, Grade 10
#12.14
#12.14

Divisibility for All \(k\)

Divisibility Grade 9 Grade 10 ★★★☆☆

Prove that \(13\mid 5^{12k}-1\) for every positive integer \(k\).

Details
Problem: NT-B1-M07-P014
Difficulty: Level 3 of 5
Tag: Divisibility
Grade: Grade 9, Grade 10
#12.15
#12.15

Last Two Digits of \(9^{2026}\)

Last Two Digits Grade 9 Grade 10 ★★★☆☆

Find the last two digits of \(9^{2026}\).

Details
Problem: NT-B1-M07-P015
Difficulty: Level 3 of 5
Tag: Last Two Digits
Grade: Grade 9, Grade 10
#12.16
#12.16

Remainder Modulo \(28\)

Modular Arithmetic Grade 9 Grade 10 ★★★☆☆

Find the remainder of \(3^{2026}\) modulo \(28\).

Details
Problem: NT-B1-M07-P016
Difficulty: Level 3 of 5
Tag: Modular Arithmetic
Grade: Grade 9, Grade 10
#12.17
#12.17

Fermat Form \(a^p-a\)

Divisibility Grade 9 Grade 10 ★★★☆☆

Prove that for every prime \(p\) and every integer \(a\), the number \(a^p-a\) is divisible by \(p\).

Details
Problem: NT-B1-M07-P017
Difficulty: Level 3 of 5
Tag: Divisibility
Grade: Grade 9, Grade 10
#12.18
#12.18

Inverse Through a Power

Fermat Grade 9 Grade 10 ★★★☆☆

Let \(p\) be prime and \(p\nmid a\). Prove that \(a^{p-2}\) is the inverse of \(a\) modulo \(p\).

Details
Problem: NT-B1-M07-P018
Difficulty: Level 3 of 5
Tag: Fermat
Grade: Grade 9, Grade 10
#12.19
#12.19

Inverse of \(7\)

Fermat Grade 9 Grade 10 ★★★☆☆

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

Details
Problem: NT-B1-M07-P019
Difficulty: Level 3 of 5
Tag: Fermat
Grade: Grade 9, Grade 10
#12.20
#12.20

A Short Cycle Modulo \(31\)

Order Grade 9 Grade 10 ★★★☆☆

Find the remainder of \(2^{1000}\) modulo \(31\).

Details
Problem: NT-B1-M07-P020
Difficulty: Level 3 of 5
Tag: Order
Grade: Grade 9, Grade 10
#12.21
#12.21

Prime Divisors of \(2^p+1\)

Divisibility Grade 9 Grade 10 ★★★★☆

Find all primes \(p\) such that \(p\mid 2^p+1\).

Details
Problem: NT-B1-M07-P021
Difficulty: Level 4 of 5
Tag: Divisibility
Grade: Grade 9, Grade 10
#12.22
#12.22

A Divisor of \(a^2+1\)

Prime Numbers Grade 9 Grade 10 ★★★★☆

Let \(p\) be an odd prime, \(p\mid a^2+1\), and \(p\nmid a\). Prove that \(p\equiv1\pmod4\).

Details
Problem: NT-B1-M07-P022
Difficulty: Level 4 of 5
Tag: Prime Numbers
Grade: Grade 9, Grade 10
#12.23
#12.23

Primes \(p\) and \(3^p+2\)

Divisibility Grade 9 Grade 10 ★★★★☆

Find all primes \(p\) such that \(p\mid 3^p+2\).

Details
Problem: NT-B1-M07-P023
Difficulty: Level 4 of 5
Tag: Divisibility
Grade: Grade 9, Grade 10
#12.24
#12.24

A Prime Divisor of a Fermat Number

Prime Numbers Grade 9 Grade 10 ★★★★★

Let \(n\ge1\), and let \(p\) be an odd prime divisor of \(2^{2^n}+1\). Prove that \(p\equiv1\pmod{2^{n+1}}\).

Details
Problem: NT-B1-M07-P024
Difficulty: Level 5 of 5
Tag: Prime Numbers
Grade: Grade 9, Grade 10

Ladders

No published ladders were found.
Previous Chapter
Next Chapter