Free Fermat's Little Theorem Calculator
Result
Enter a and p to apply Fermat's Little Theorem
Understanding Fermat's Little Theorem
Fermat's Little Theorem is a cornerstone of elementary number theory, establishing a profound link between prime numbers and modular arithmetic. This theorem states that if is a prime and is any integer, then is always divisible by . In the language of modular arithmetic, we write:
When is not a multiple of (i.e., ), the theorem can be simplified to:
This result is the foundation for many applications: primality testing, public‑key cryptography (like RSA), and computing modular inverses. While the Prime Number Theorem describes the asymptotic distribution of primes, Fermat's Little Theorem provides a concrete relationship that powers many modern algorithms. The modular arithmetic calculator based on Fermat's Little Theorem allows you to verify these congruences quickly.
Working with Examples
Let’s examine two concrete cases to see how the theorem behaves under different conditions.
Case 1: and coprime. Take and . Since 15 is not divisible by 7, the second version applies:
Calculating: ; subtract 1 yields , which equals , confirming divisibility.
Case 2: divisible by . Now consider and . Here 14 is a multiple of 7, so we must use the original form:
Indeed, is exactly , satisfying the congruence.
These examples illustrate the importance of checking the coprime condition before applying the shortened exponent form.
How to Use the Fermat's Little Theorem Calculator
The online Fermat's Little Theorem calculator — a dedicated mod calculator — simplifies the process of applying the theorem. To use it:
- Enter the two integers and .
- The tool first verifies that is indeed prime (you can also pre‑check with a prime number checker).
- It then checks whether and are coprime.
- Based on these checks, it displays the appropriate version of the theorem and shows the resulting congruence.
This mod calculator is especially useful for quickly verifying modular relationships and for educational purposes.
Finding the Multiplicative Inverse Modulo
One important application of Fermat's Little Theorem is computing the multiplicative inverse of an integer modulo a prime. From , we can rewrite this as . Therefore, the inverse of modulo is . The calculator can compute this exponentiation modulo efficiently, providing the modular inverse without complex calculations.
Using the Theorem for Primality Testing
Fermat's Little Theorem also offers a probabilistic primality test. To test whether a number is prime:
- Choose a random integer between 2 and such that .
- Compute .
- If the result is not 1, then is definitely composite.
- If the result is 1, the test is inconclusive; try a different .
- After several successful passes, is considered "probably prime."
While this test does not guarantee primality (some composites, called Carmichael numbers, may always pass), it provides a quick check. Combined with other tests, it forms the basis of many modern primality checks.
A Historical Perspective
Fermat first stated his "little" theorem in 1640 in a letter to Frénicle de Bessy, but he did not provide a proof. The first published proof came from Euler in 1736, though Leibniz had earlier discovered it privately. The theorem earned the nickname "little" to distinguish it from Fermat's Last Theorem, which concerns the equation and was finally proved by Andrew Wiles in 1995. Despite its humble name, Fermat's Little Theorem remains an essential tool in number theory and modern cryptography.
Conclusion
The Fermat's Little Theorem Calculator offers a convenient way to explore congruences and apply the theorem in various contexts, from finding modular inverses to testing primality. By understanding the statement and its conditions, you can leverage this powerful result in both theoretical and practical settings.
FAQ
1. What are the conditions required to apply Fermat's Little Theorem?
The theorem requires that p be a prime number. If using the simplified form a^(p-1) ≡ 1 (mod p), a must not be divisible by p (i.e., gcd(a,p)=1). The original form a^p ≡ a (mod p) holds for any integer a.
2. How can I compute the multiplicative inverse of a number modulo a prime using this theorem?
From a^(p-1) ≡ 1 (mod p) we get a * a^(p-2) ≡ 1 (mod p). Therefore the inverse of a modulo p is a^(p-2). The calculator can compute this modular exponentiation for you.
3. How reliable is Fermat's Little Theorem for testing whether a number is prime?
If a^(p-1) mod p ≠ 1 for some a coprime to p, then p is definitely composite. If the congruence holds for many random a, p is likely prime but not guaranteed, because certain composites (Carmichael numbers) also satisfy the condition. It is a probabilistic test.
4. What is the difference between Fermat's Little Theorem and Fermat's Last Theorem?
Fermat's Little Theorem deals with congruences modulo a prime: a^p ≡ a (mod p). Fermat's Last Theorem states that the equation x^n + y^n = z^n has no positive integer solutions for integer n > 2. They are entirely different results; the 'little' theorem is widely used in cryptography, while the 'last' theorem remained unsolved for over 350 years.
How to Use
- Enter the integer a in the first input field.
- Enter a prime number p as the modulus in the second input field.
- The calculator displays the appropriate Fermat's Little Theorem statement and the computation result.