Sign in to save

Bookmark this page so you can find it later.

Sign in to save

Bookmark this page so you can find it later.

Fermat's Little Theorem is a key result in number theory that helps simplify powers in modular arithmetic. This cheat sheet covers the theorem, when it applies, and how it is used to find remainders and modular inverses. Students need it because large exponent problems become manageable when powers repeat in predictable cycles.

It is especially useful for contest math, cryptography basics, and advanced algebra topics.

The main idea is that if pp is prime and aa is not divisible by pp, then ap11(modp)a^{p-1} \equiv 1 \pmod{p}. This means exponents can often be reduced modulo p1p-1 when working mod pp. A related form says apa(modp)a^p \equiv a \pmod{p} for any integer aa.

Applications include computing large remainders, checking divisibility patterns, and finding inverses using a1ap2(modp)a^{-1} \equiv a^{p-2} \pmod{p}.

Key Facts

  • If pp is prime and gcd(a,p)=1\gcd(a,p)=1, then Fermat's Little Theorem states ap11(modp)a^{p-1} \equiv 1 \pmod{p}.
  • For any integer aa and prime pp, the equivalent form apa(modp)a^p \equiv a \pmod{p} is always true.
  • When pp is prime and gcd(a,p)=1\gcd(a,p)=1, exponents can be reduced using anar(modp)a^n \equiv a^{r} \pmod{p} where rn(modp1)r \equiv n \pmod{p-1}.
  • If pp is prime and pap \nmid a, the modular inverse of aa modulo pp is a1ap2(modp)a^{-1} \equiv a^{p-2} \pmod{p}.
  • The condition gcd(a,p)=1\gcd(a,p)=1 is required for the form ap11(modp)a^{p-1} \equiv 1 \pmod{p}.
  • If ab(modm)a \equiv b \pmod{m}, then anbn(modm)a^n \equiv b^n \pmod{m} for any positive integer nn.
  • To compute a large power like an(modp)a^n \pmod{p}, first reduce aa modulo pp, then reduce nn modulo p1p-1 when pp is prime and pap \nmid a.
  • Fermat's Little Theorem does not prove that pp is prime just because ap11(modp)a^{p-1} \equiv 1 \pmod{p} holds for one value of aa.

Vocabulary

Prime modulus
A modulus pp that is a prime number, which is required for the standard form of Fermat's Little Theorem.
Congruence
A statement ab(modm)a \equiv b \pmod{m} meaning that aa and bb have the same remainder when divided by mm.
Relatively prime
Two integers aa and bb are relatively prime when gcd(a,b)=1\gcd(a,b)=1.
Modular inverse
The modular inverse of aa modulo mm is a number xx such that ax1(modm)ax \equiv 1 \pmod{m}.
Exponent reduction
Exponent reduction is the process of replacing a large exponent with a smaller congruent exponent, often using nr(modp1)n \equiv r \pmod{p-1}.
Remainder class
A remainder class is the set of all integers that are congruent to the same value modulo mm.

Common Mistakes to Avoid

  • Using ap11(modp)a^{p-1} \equiv 1 \pmod{p} when pap \mid a is wrong because the theorem requires gcd(a,p)=1\gcd(a,p)=1 for that form.
  • Applying Fermat's Little Theorem with a composite modulus is wrong because ap11(modp)a^{p-1} \equiv 1 \pmod{p} is guaranteed only when pp is prime.
  • Reducing the exponent modulo pp instead of modulo p1p-1 is wrong because the power cycle from Fermat's Little Theorem has length dividing p1p-1.
  • Changing a0a^0 to 00 is wrong because a0=1a^0=1 for a0a \neq 0, so an exponent reduction that gives r=0r=0 usually means an1(modp)a^n \equiv 1 \pmod{p}.
  • Assuming one successful Fermat test proves primality is wrong because some composite numbers can satisfy an11(modn)a^{n-1} \equiv 1 \pmod{n} for certain bases aa.

Practice Questions

  1. 1 Find the remainder when 71007^{100} is divided by 1313.
  2. 2 Find the modular inverse of 88 modulo 1717 using Fermat's Little Theorem.
  3. 3 Compute 32025(mod11)3^{2025} \pmod{11}.
  4. 4 Explain why Fermat's Little Theorem can be used to reduce the exponent in 51234(mod19)5^{1234} \pmod{19}, but not directly in 61234(mod21)6^{1234} \pmod{21}.

Understanding Fermat's Little Theorem & Applications

A useful way to understand the result is to look at multiplication by a number modulo a prime. Take a nonzero remainder, such as three modulo seven, and multiply every nonzero remainder by three. The results are three, six, two, five, one, and four.

None repeat before every possible nonzero remainder has appeared. This happens because a repeated result would mean that two different numbers have the same remainder after multiplication by three. Since three has an inverse modulo seven, that would force the original numbers to have been equal.

Thus multiplication simply rearranges the nonzero remainders. Comparing the product before and after this rearrangement leads to the power rule.

The repeating pattern of powers can be shorter than the length promised by the theorem. For example, powers of two modulo seven go two, four, one, then repeat. The cycle length is three, even though the prime minus one is six.

This shorter length is called the order of the number modulo the prime. Reducing an exponent by the prime minus one is always safe under the required conditions, but finding the shorter cycle can make hand calculations faster.

Students should first list a few powers when the modulus is small. This reveals patterns and gives a check on any exponent reduction.

Modular inverses turn division into multiplication. Ordinary division is not usually meaningful when only remainders matter. Instead, to divide by a number, find a number whose product with it leaves remainder one.

For instance, the inverse of three modulo seven is five because three times five leaves remainder one upon division by seven. Therefore a congruence involving three times a value can be solved by multiplying both sides by five.

The power method for inverses works for prime moduli, though the extended Euclidean algorithm is often quicker for actual calculations. That algorithm works whenever the number and modulus have greatest common divisor one, even if the modulus is not prime.

The prime condition deserves careful attention. With a composite modulus, nonzero remainders can fail to have inverses. For example, two times three is zero modulo six, even though neither factor is zero modulo six.

This kind of zero product cannot happen modulo a prime. It explains why prime moduli behave so cleanly. In cryptography, large prime numbers are chosen partly because inverse calculations are reliable in these systems.

However, the theorem is not a shortcut for declaring a number prime. Some composite numbers pass the power test for certain bases.

When solving school problems, state the modulus, check whether it is prime, reduce the base first, then decide whether the exponent rule is allowed. These habits prevent most common errors.