<P> The simplest probabilistic primality test is the Fermat primality test (actually a compositeness test). It works as follows: </P> <Dl> <Dd> Given an integer n, choose some integer a coprime to n and calculate a modulo n . If the result is different from 1, then n is composite . If it is 1, then n may be prime . </Dd> </Dl> <Dd> Given an integer n, choose some integer a coprime to n and calculate a modulo n . If the result is different from 1, then n is composite . If it is 1, then n may be prime . </Dd> <P> If a (modulo n) is 1 but n is not prime, then n is called a pseudoprime to base a . In practice, we observe that, if a (modulo n) is 1, then n is usually prime . But here is a counterexample: if n = 341 and a = 2, then </P>

Efficient way to check if number is prime