Fermat's Theorem: Formula, Rules, Examples and Applications
Fermat's Theorem gives a method for simplifying powers in modular arithmetic when the modulus is prime. For a prime number p and an integer a not divisible by p, a^(p−1) leaves remainder 1 when divided by p. This page covers the theorem formula, exponent reduction, modular inverses, special cases and solved numerical examples.
What is Fermat's Theorem?
The notation a ≡ b (mod p) means that a and b have the same remainder on division by p. In the first form, the condition gcd(a,p)=1 is required. For example, since 5 is prime and 3 is not divisible by 5, 3^4 ≡ 1 (mod 5). Therefore, 3^8 ≡ 1 (mod 5).
Fermat's Theorem Formula & Tricks
Important Formulas
Here, p ∤ a means that p does not divide a. The exponent can be reduced in multiples of p−1 when the base is relatively prime to p.
This form also works when p divides a. It follows from the standard form when p does not divide a, and is immediate when p divides a.
The value a^(p−2) is the multiplicative inverse of a modulo p because a × a^(p−2) = a^(p−1) ≡ 1 (mod p).
Quick Tricks
For a prime modulus p and a base not divisible by p, replace a large exponent n by its remainder when divided by p−1. If n = q(p−1)+r, then a^n ≡ a^r (mod p).
Exponent reduction modulo p−1 is not directly valid when p divides the base. In that case, use a^p ≡ a (mod p) or calculate the power using divisibility.
A division by a modulo p can be changed to multiplication by a^(p−2), provided p does not divide a.
Fermat's Theorem Concepts
Exponent reduction under a prime modulus
For n = q(p−1)+r, Fermat's theorem gives a^n = a^[q(p−1)+r] ≡ (a^(p−1))^q × a^r ≡ a^r (mod p). The remainder r may be zero; in that case a^n ≡ 1 (mod p).
The two equivalent forms of the theorem
If p does not divide a, multiplying a^(p−1) ≡ 1 by a gives a^p ≡ a. If p divides a, both sides of a^p ≡ a are congruent to 0 modulo p.
Finding a modular inverse
An inverse x satisfies ax ≡ 1 (mod p). Since a^(p−1) ≡ 1 (mod p), taking x = a^(p−2) gives ax = a^(p−1) ≡ 1 (mod p).
Conditions and limitations
The rule a^(p−1) ≡ 1 (mod p) should not be applied when the modulus is composite or when p divides a. For a composite modulus, Euler's theorem or direct modular calculation may be appropriate, but the exponent period is not generally n−1.
Fermat's Theorem Video Lessons
Watch short topic-wise lessons for quick revision.
Remainder Tricks: Fermat and Euler
Learn how Fermat’s pattern and Euler’s approach simplify remainder calculations for powers, including the key conditions and steps needed to apply these methods accurately.
Practice Fermat's Theorem Questions
Practise published questions related to this topic.
Fermat's Theorem Quick Quiz
Attempt 5 questions and check your score instantly.
Keep practising
Practice more Fermat's Theorem questions in the PrepShots app and continue from your current topic.
Practice More Questions - Start ₹1 Trial →Quick Revision Notes
Fermat's Theorem: Quick Revision
Use these conditions and formulas when simplifying powers modulo a prime.
- For prime p and p ∤ a: a^(p−1) ≡ 1 (mod p).
- For every integer a and prime p: a^p ≡ a (mod p).
- When p ∤ a, reduce a large exponent modulo p−1.
- If p divides the base, do not apply the standard exponent-reduction form directly.
- For p ∤ a, the modular inverse is a^−1 ≡ a^(p−2) (mod p).
- The standard Fermat formula requires a prime modulus; it is not a general rule for composite moduli.
Fermat's Theorem FAQs
What is the formula for Fermat's Theorem?
If p is prime and p does not divide a, then a^(p−1) ≡ 1 (mod p). Its universal form is a^p ≡ a (mod p) for every integer a.
How do you calculate 2^100 modulo 7 using Fermat's Theorem?
Since 7 is prime, reduce 100 modulo 6: 100 ≡ 4 (mod 6). Therefore, 2^100 ≡ 2^4 = 16 ≡ 2 (mod 7).
Can the exponent be reduced modulo p−1 when the base is divisible by p?
No. The reduction modulo p−1 requires p ∤ a. For example, 5^100 modulo 5 is 0, while reducing the exponent using the standard form would not be valid.
What is the modular inverse of 2 modulo 13 using Fermat's theorem?
The inverse is 2^(13−2) = 2^11 modulo 13. Since 2^12 ≡ 1 (mod 13), 2^11 ≡ 7 (mod 13), and 2 × 7 = 14 ≡ 1 (mod 13).
Does Fermat's Theorem apply when the modulus is composite?
The standard form a^(n−1) ≡ 1 (mod n) is not generally valid for composite n. For example, 3^7 ≡ 3 (mod 8), not 1; the modulus 8 is composite.
