Intro to Fermat's Little Theorem
Intro to Fermat's Little Theorem
CX330Prologue
Fermat’s Little Theorem is quite often seen in the CTF contests, so let’s dive in to this article to know more about it! Math is powerful!
Required Knowledge
Statement
If is a prime, and is an arbitrary integer which is coprime with , then the following relationship is satisfied.
This means, if we devided by , the remainder will be 1. Mathematically, if we repeatedly multiply an integer , which is coprime to a prime , until reaching , the result will be congruent to 1 modulo .
Example
Suppose , and . Since and are coprime, so we can apply the Fermat’s Little Theorem.
Then calculate
The remainder is so,
Generalization & Application
- Fast Exponentiation
- Fermat’s Little Theorem is often used to simplify modular exponention. For large exponents, applying this Theorem can significantly reduce the computational complexity.
- For example, to compute , one can first reduce modulo , transforming it into a smaller exponent before calculating.
- RSA Encryption & Decryption
- Verifying Congruence Relations
- Fermat’s Little Theorem is also frequently used to verify specific congruence properties in modular arithmetic, making it an essential tool in number theory proofs.
The Generalization of Euler’s Theorem
Fermat’s Little Theorem is a special case of Euler’s Theorem. Euler’s Theorem applies to all integers that are coprime with , and its form is as follows.
Where is Euler’s function, representing the numbers of positive integers less than that are coprime to . When is a prime number, , and Eular’s Theorem simplifies to Fermat’s Little Theorem.