Teste Fermat primalidade

a^(p−1) ≡ 1 (mod p).
Created by
Renato Passos, Eng. de Software
Reviewed by
Renato Passos, Eng. de Software

Last updated: Apr 18, 2026

resíduo
1

About this calculator

The Fermat's Little Theorem primality test calculator is an online tool that uses Fermat's Little Theorem to check if a number is prime. Fermat's Little Theorem states that if p is a prime number, then for any integer a not divisible by p, a^(p-1) ≡ 1 (mod p). In other words, if a number p is prime, then a raised to the power of p-1, modulo p, equals 1.

This calculator works by applying the theorem to a number p and a randomly chosen value a. If the result is not 1, then p is definitely not prime. However, if the result is 1, it's not possible to be certain that p is prime, as there are composite numbers that also satisfy the condition, known as pseudoprimes. Therefore, this calculator provides a probabilistic primality test.

The Fermat test is particularly useful for large numbers, as it is computationally more efficient than other primality verification methods. However, it's essential to keep in mind that, although rare, there is a possibility that a number might be erroneously reported as prime. For critical applications, more rigorous methods may be necessary.

To use this calculator, simply enter the number you want to test and the value of a. The calculator will then compute a^(p-1) mod p and display the result. If you get 1, the number is likely prime, but for absolute confirmation, especially in critical contexts, it's recommended to use additional primality tests.

Frequently asked questions

What is Fermat's Little Theorem?

Fermat's Little Theorem states that if p is a prime number, then for any integer a not divisible by p, a^(p-1) ≡ 1 (mod p).

Can this calculator definitively state if a number is prime?

No, this calculator provides a probabilistic primality test. If the result is 1, the number is likely prime, but there is no absolute guarantee.

What are the limitations of the Fermat test?

The Fermat test can yield false positives for composite numbers that are pseudoprimes. For absolute confirmation of primality, more rigorous methods are required.

For what types of applications is the Fermat test most suitable?

The Fermat test is particularly useful for large numbers and in situations where a quick and probabilistic primality test is sufficient, such as in many cryptographic applications.

How to choose the value of a for the test?

The value of a should be an integer not divisible by p. In practice, any value of a between 2 and p-1 can be chosen; small values are more common for computational simplicity.

Other Teoria Números calculators