A computer test of a very fast primarily test

77 Views Asked by At

Fermat's little theorem states that if $p$ is a prime and $a$ is any integer not divisible by $p$, then $a^{p-1} - 1$ is divisible by $p$. $$a^{p-1}\equiv 1\pmod p$$

This can be used to test if a number $n$ is a composite, which is implied of $a^{n-1}\not\equiv 1\pmod n$ for any $a$ not divisible by $n$. I have ran a test for pseudo random generated single cell numbers with the number $x$ of binary digits, to get the number of tests before a composite number $n$ gives $(n-2)^{n-1}\equiv 1\pmod n$ and got the following diagram:

enter image description here Assuming that my computer test is accurate, how to estemate the probability of an error using Fermat as an primality test for big numbers?

The test takes about 0.02 seconds on my computer for a number with $100$ binary digits. How to estimate the probability of getting a "false prime" by testing $100,000,000,000$ times ($100$-digit) pseudo random numbers, which would take about 80 years? Is it possible to say something about the accuracy of the estimation?