<s>
The	O
Fermat	B-Algorithm
primality	I-Algorithm
test	I-Algorithm
is	O
a	O
probabilistic	B-General_Concept
test	O
to	O
determine	O
whether	O
a	O
number	O
is	O
a	O
probable	B-Algorithm
prime	I-Algorithm
.	O
</s>
<s>
Therefore	O
,	O
if	O
the	O
equality	O
does	O
hold	O
for	O
one	O
or	O
more	O
values	O
of	O
a	O
,	O
then	O
we	O
say	O
that	O
p	O
is	O
probably	B-Algorithm
prime	I-Algorithm
.	O
</s>
<s>
when	O
n	O
is	O
composite	O
is	O
known	O
as	O
a	O
Fermat	B-Algorithm
liar	I-Algorithm
.	O
</s>
<s>
In	O
this	O
case	O
n	O
is	O
called	O
Fermat	B-Algorithm
pseudoprime	I-Algorithm
to	O
base	O
a	O
.	O
</s>
<s>
then	O
a	O
is	O
known	O
as	O
a	O
Fermat	B-Algorithm
witness	I-Algorithm
for	O
the	O
compositeness	O
of	O
n	O
.	O
</s>
<s>
Either	O
221	O
is	O
prime	O
,	O
or	O
38	O
is	O
a	O
Fermat	B-Algorithm
liar	I-Algorithm
,	O
so	O
we	O
take	O
another	O
a	O
,	O
say	O
24	O
:	O
</s>
<s>
So	O
221	O
is	O
composite	O
and	O
38	O
was	O
indeed	O
a	O
Fermat	B-Algorithm
liar	I-Algorithm
.	O
</s>
<s>
Furthermore	O
,	O
24	O
is	O
a	O
Fermat	B-Algorithm
witness	I-Algorithm
for	O
the	O
compositeness	O
of	O
221	O
.	O
</s>
<s>
Using	O
fast	O
algorithms	O
for	O
modular	O
exponentiation	O
and	O
multiprecision	O
multiplication	O
,	O
the	O
running	O
time	O
of	O
this	O
algorithm	O
is	O
,	O
where	O
k	O
is	O
the	O
number	O
of	O
times	O
we	O
test	O
a	O
random	O
a	O
,	O
and	O
n	O
is	O
the	O
value	O
we	O
want	O
to	O
test	O
for	O
primality	O
;	O
see	O
Miller	B-Algorithm
–	I-Algorithm
Rabin	I-Algorithm
primality	I-Algorithm
test	I-Algorithm
for	O
details	O
.	O
</s>
<s>
There	O
are	O
infinitely	O
many	O
Fermat	B-Algorithm
pseudoprimes	I-Algorithm
to	O
any	O
given	O
basis	O
a>1	O
.	O
</s>
<s>
These	O
are	O
numbers	O
for	O
which	O
all	O
values	O
of	O
with	O
are	O
Fermat	B-Algorithm
liars	I-Algorithm
.	O
</s>
<s>
For	O
these	O
numbers	O
,	O
repeated	O
application	O
of	O
the	O
Fermat	B-Algorithm
primality	I-Algorithm
test	I-Algorithm
performs	O
the	O
same	O
as	O
a	O
simple	O
random	O
search	O
for	O
factors	O
.	O
</s>
<s>
While	O
Carmichael	O
numbers	O
are	O
substantially	O
rarer	O
than	O
prime	O
numbers	O
(	O
Erdös	O
 '	O
upper	O
bound	O
for	O
the	O
number	O
of	O
Carmichael	O
numbers	O
is	O
lower	O
than	O
the	O
prime	O
number	O
function	O
n/log	O
( n	O
)	O
)	O
there	O
are	O
enough	O
of	O
them	O
that	O
Fermat	B-Algorithm
's	I-Algorithm
primality	I-Algorithm
test	I-Algorithm
is	O
not	O
often	O
used	O
in	O
the	O
above	O
form	O
.	O
</s>
<s>
Instead	O
,	O
other	O
more	O
powerful	O
extensions	O
of	O
the	O
Fermat	B-Algorithm
test	I-Algorithm
,	O
such	O
as	O
Baillie	B-Algorithm
–	I-Algorithm
PSW	I-Algorithm
,	O
Miller	B-Algorithm
–	I-Algorithm
Rabin	I-Algorithm
,	O
and	O
Solovay	O
–	O
Strassen	O
are	O
more	O
commonly	O
used	O
.	O
</s>
<s>
For	O
proof	O
of	O
this	O
,	O
let	O
be	O
a	O
Fermat	B-Algorithm
witness	I-Algorithm
and	O
,	O
,	O
...	O
,	O
be	O
Fermat	B-Algorithm
liars	I-Algorithm
.	O
</s>
<s>
As	O
mentioned	O
above	O
,	O
most	O
applications	O
use	O
a	O
Miller	B-Algorithm
–	I-Algorithm
Rabin	I-Algorithm
or	O
Baillie	B-Algorithm
–	I-Algorithm
PSW	I-Algorithm
test	O
for	O
primality	O
.	O
</s>
<s>
Sometimes	O
a	O
Fermat	B-Algorithm
test	I-Algorithm
(	O
along	O
with	O
some	O
trial	O
division	O
by	O
small	O
primes	O
)	O
is	O
performed	O
first	O
to	O
improve	O
performance	O
.	O
</s>
<s>
GMP	B-Application
since	O
version	O
3.0	O
uses	O
a	O
base-210	O
Fermat	B-Algorithm
test	I-Algorithm
after	O
trial	O
division	O
and	O
before	O
running	O
Miller	B-Algorithm
–	I-Algorithm
Rabin	I-Algorithm
tests	I-Algorithm
.	O
</s>
<s>
Libgcrypt	B-Application
uses	O
a	O
similar	O
process	O
with	O
base	O
2	O
for	O
the	O
Fermat	B-Algorithm
test	I-Algorithm
,	O
but	O
OpenSSL	B-Language
does	O
not	O
.	O
</s>
<s>
In	O
practice	O
with	O
most	O
big	O
number	O
libraries	O
such	O
as	O
GMP	B-Application
,	O
the	O
Fermat	B-Algorithm
test	I-Algorithm
is	O
not	O
noticeably	O
faster	O
than	O
a	O
Miller	B-Algorithm
–	I-Algorithm
Rabin	I-Algorithm
test	I-Algorithm
,	O
and	O
can	O
be	O
slower	O
for	O
many	O
inputs	O
.	O
</s>
<s>
As	O
an	O
exception	O
,	O
OpenPFGW	O
uses	O
only	O
the	O
Fermat	B-Algorithm
test	I-Algorithm
for	O
probable	B-Algorithm
prime	I-Algorithm
testing	O
.	O
</s>
<s>
Another	O
well	O
known	O
program	O
that	O
relies	O
only	O
on	O
the	O
Fermat	B-Algorithm
test	I-Algorithm
is	O
PGP	B-Application
where	O
it	O
is	O
only	O
used	O
for	O
testing	O
of	O
self-generated	O
large	O
random	O
values	O
(	O
an	O
open	O
source	O
counterpart	O
,	O
GNU	B-Application
Privacy	I-Application
Guard	I-Application
,	O
uses	O
a	O
Fermat	O
pretest	O
followed	O
by	O
Miller	B-Algorithm
–	I-Algorithm
Rabin	I-Algorithm
tests	I-Algorithm
)	O
.	O
</s>
