Sub topic 9
Fermat's Little Theorem
Assume you can factor integers, identify prime numbers, and work with remainders. Fermat's little theorem is a shortcut for reducing large powers modulo a prime number.
The theorem
If \(p\) is prime and \(a\) is not divisible by \(p\), then
\[ a^{p-1} \equiv 1 \pmod p \]
The notation means that \(a^{p-1}\) leaves remainder \(1\) when divided by \(p\).
For example, \(13\) is prime and \(2\) is not divisible by \(13\). Therefore,
\[ 2^{12} \equiv 1 \pmod {13} \]
This lets us reduce large exponents in powers of \(2\) modulo \(13\).
Worked example: a large power
Find the remainder when \(2^{100}\) is divided by \(13\).
Since \(13\) is prime,
\[ 2^{12} \equiv 1 \pmod {13} \]
Rewrite the exponent:
\[ 100 = 12 \times 8 + 4 \]
Thus,
\[ 2^{100} = (2^{12})^8 \times 2^4 \]
Taking remainders,
\[ 2^{100} \equiv 1^8 \times 2^4 \pmod {13} \]
Since \(2^4=16\equiv3\pmod {13}\),
\[ \boxed{2^{100}\equiv3\pmod {13}} \]
Python confirms the result:
print(pow(2, 100, 13)) # 3The three-argument form of pow calculates a modular power efficiently. It calculates \(2^{100}\bmod13\) without first storing the enormous value of \(2^{100}\).
Common errors
| Error | Why it is wrong | Correction |
|---|---|---|
| Using \(p-1\) when the modulus is not prime | Fermat's theorem requires a prime modulus | Check the modulus first |
| Applying the theorem when \(p\) divides \(a\) | The condition \(p\nmid a\) is required | Reduce the base and inspect divisibility |
| Replacing the exponent with its remainder without explanation | The reduction follows from \(a^{p-1}\equiv1\) | Write the exponent as \(k(p-1)+r\) |
| Forgetting the final small power | The exponent usually has a nonzero remainder | Calculate \(a^r\) modulo \(p\) |
A useful equivalent form is
\[ a^p \equiv a \pmod p \]
This version works for every integer \(a\), including multiples of \(p\). However, for reducing a nonzero base's exponent, the \(p-1\) form is usually more direct.
Exam method
For a question involving \(a^n\bmod p\):
- Confirm that \(p\) is prime.
- Confirm that \(p\) does not divide \(a\).
- Calculate \(n\bmod(p-1)\).
- Replace the exponent with that smaller remainder.
- Find the remaining small power.
If the reduced exponent is \(0\), use \(a^0=1\). This is valid because the original power is a positive multiple of \(p-1\).
Exercise
Find the remainder when 3^50 is divided by 7.
Show answer
Since 7 is prime, 3^6 ≡ 1 (mod 7). Because 50 ≡ 2 (mod 6), 3^50 ≡ 3^2 ≡ 2 (mod 7). The remainder is 2.