What is Fermat's theorem?

Fermat's theorem, also called Fermat's little theorem, states that apaa^p - a is an integer multiple of pp, if pp is a prime number and aa is an integer. The mathematical form of the theorem is as follows:

Additionally, an alternate form of the above-mentioned equation exists. The mathematical form of Fermat's alternate form is as follows:

It is valid only if the integer aa is not divisible by the prime number pp. This is unlike the original form, which is valid even when the integer aa is not divisible by the prime number pp. The alternate form states that ap11a^{p-1} - 1 is an integer multiple of pp.

The validity of Fermat's theorem

We can check the validity of Fermat's theorem's original and alternate forms by applying different combinations of aa and pp to the equation.

The original form

To validate the original form, we consider two examples:

Example 1

Given a=2a = 2 and p=3p = 3, we know that aa is not divisible by pp. Next, we plug the values into the original Fermat equation, as follows:

Now, we simplify it by writing the equation in its original form apaa^p - a, and calculating if the result of this is a multiple of the prime number pp, as follows:

We can verify that 66 is a multiple of 33:

This proves that Fermat's original theorem is valid when aa is not divisible by pp.

Example 2

Given a=6a = 6 and p=3p = 3, we know that aa is divisible by pp. Next, we plug the values into the original Fermat equation, as follows:

Now, we simplify it by writing the equation in its original form apaa^p - a, and calculating if the result of this is a multiple of the prime number pp.

We can verify that 210210 is a multiple of 33:

This proves that Fermat's original theorem is valid when aa is divisible by pp.

The alternate form

To validate the alternate form, we consider two examples.

Example 1

Given a=2a = 2 and p=5p = 5, we know that aa is not divisible by pp. Next, we plug the values into the alternate Fermat equation, as follows:

Now, we simplify it by writing the equation in its original form ap11a^{p-1} - 1, and calculating if the result of this is a multiple of the prime number pp, as follows:

We can verify that 1515 is a multiple of 55:

This proves that Fermat's alternate form is valid when aa is not divisible by pp.

Example 2

Given a=10a = 10 and p=5p = 5, we know that aa is divisible by pp. Next, we plug the values into the alternate Fermat equation, as follows:

Now, we simplify it by writing the equation in its original form ap11a^{p-1} - 1, and calculating if the result of this is a multiple of the prime number pp, as follows:

We can verify that 99999999 is not a multiple of 55, as it leaves a remainder of 44 when divided by 99999999. This proves that Fermat's alternate form is not valid when aa is not divisible by pp.

Application

Fermat's theorem is used as an underlying base for Euler's theorem. Euler's theorem is a generalization of Fermat's theorem. It extends Fermat's theorem, which allows it to be used as the base for the RSA algorithm. Thus, Fermat's theorem is a core part of modern-era cryptography.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved