Skip to main content
AMC 12 focus

Fermat, Euler & Orders

Two named theorems that shortcut huge modular powers, plus the idea of an element's order — how long its power cycle actually is.

Fermat’s Little Theorem

If pp is prime and gcd(a,p)=1\gcd(a,p)=1:

ap11(modp)a^{p-1} \equiv 1 \pmod p

An equivalent form that works even when pap \mid a: apa(modp)a^p \equiv a \pmod p.

Euler’s theorem

Euler’s theorem generalizes Fermat’s to any modulus, not just primes, using Euler’s totient function φ(m)\varphi(m) (the count of integers from 1 to mm that are coprime tomm):

aφ(m)1(modm)whenever gcd(a,m)=1a^{\varphi(m)} \equiv 1 \pmod m \qquad\text{whenever } \gcd(a,m)=1

For a prime pp, φ(p)=p1\varphi(p) = p-1, recovering Fermat’s theorem as a special case.

Multiplicative order

The order of aa modulo mm is the smallest positive integer kk such that ak1(modm)a^k \equiv 1 \pmod m. The order always exists when gcd(a,m)=1\gcd(a,m)=1, and — this is the key structural fact — the order always divides φ(m)\varphi(m), and more generally divides any exponent nn for which an1(modm)a^n \equiv 1 \pmod m. This is often the fastest way to find an exponent cycle length: it must be a divisor of φ(m)\varphi(m), so you only need to test those divisors rather than every possible length.

Worked example

Problem: Find the last two digits of 720247^{2024} (i.e. 72024mod1007^{2024} \bmod 100).

Solution: gcd(7,100)=1\gcd(7,100)=1, and φ(100)=φ(4)φ(25)=2×20=40\varphi(100)=\varphi(4)\varphi(25)=2\times20=40. By Euler’s theorem, 7401(mod100)7^{40}\equiv1\pmod{100}. Reduce the exponent:

2024=40×50+24    72024724(mod100)2024 = 40\times50+24 \;\Longrightarrow\; 7^{2024}\equiv7^{24}\pmod{100}

Computing 724mod1007^{24} \bmod 100 by repeated squaring: 72=497^2=49,74=492=240117^4=49^2=2401\equiv1, so 741(mod100)7^4 \equiv 1 \pmod{100} already (the actual order divides 40 and turns out to be 4). Then 724=(74)616=1(mod100)7^{24}=(7^4)^6\equiv1^6=1 \pmod{100}.

So the last two digits of 720247^{2024} are 01.

Practice problems

1.Use Fermat’s Little Theorem to find 212mod132^{12} \bmod 13.

2.Find φ(12)\varphi(12).

3.Find the remainder when 52035^{203} is divided by 13, using Fermat’s theorem.

4.What is the order of 3 modulo 7?