Free Fermat's Little Theorem Calculator

ap-1

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 pp is a prime and aa is any integer, then ap−aa^{p} - a is always divisible by pp. In the language of modular arithmetic, we write:

ap≡a(modp)a^{p} \equiv a \pmod{p}

When aa is not a multiple of pp (i.e., gcd⁡(a,p)=1\gcd(a,p)=1), the theorem can be simplified to:

ap−1≡1(modp)a^{p-1} \equiv 1 \pmod{p}

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: aa and pp coprime. Take p=7p=7 and a=15a=15. Since 15 is not divisible by 7, the second version applies:

156≡1(mod7)15^{6} \equiv 1 \pmod{7}

Calculating: 156=11,390,62515^{6} = 11,390,625; subtract 1 yields 11,390,62411,390,624, which equals 7×1,627,2327 \times 1,627,232, confirming divisibility.

Case 2: aa divisible by pp. Now consider p=7p=7 and a=14a=14. Here 14 is a multiple of 7, so we must use the original form:

147≡14(mod7)14^{7} \equiv 14 \pmod{7}

Indeed, 147−14=105,413,50414^{7} - 14 = 105,413,504 is exactly 7×15,059,0707 \times 15,059,070, 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:

  1. Enter the two integers aa and pp.
  2. The tool first verifies that pp is indeed prime (you can also pre‑check with a prime number checker).
  3. It then checks whether aa and pp are coprime.
  4. 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 pp

One important application of Fermat's Little Theorem is computing the multiplicative inverse of an integer modulo a prime. From ap−1≡1(modp)a^{p-1} \equiv 1 \pmod{p}, we can rewrite this as a⋅ap−2≡1(modp)a \cdot a^{p-2} \equiv 1 \pmod{p}. Therefore, the inverse of aa modulo pp is ap−2a^{p-2}. The calculator can compute this exponentiation modulo pp 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 pp is prime:

  • Choose a random integer aa between 2 and p−2p-2 such that gcd⁡(a,p)=1\gcd(a,p)=1.
  • Compute ap−1 mod pa^{p-1} \bmod p.
  • If the result is not 1, then pp is definitely composite.
  • If the result is 1, the test is inconclusive; try a different aa.
  • After several successful passes, pp 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 xn+yn=znx^{n} + y^{n} = z^{n} 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

  1. Enter the integer a in the first input field.
  2. Enter a prime number p as the modulus in the second input field.
  3. The calculator displays the appropriate Fermat's Little Theorem statement and the computation result.