TITLE: How to check if a large number is prime?
QUESTION [5 upvotes]: Is $31!+1$ a prime number?
Prime numbers can be written as $6n+1$ or $6n-1$ form.
$31!+1$ can also be written as $6n+1$,but not every number of the form $6n+1$ is prime.
How do I proceed efficiently?

REPLY [2 votes]: The simplest test is to start with trial division by small primes.  Your statement that it is $6n+1$ represents trial division by $2$ and $3$.  You can keep going until you get tired.  Then try Fermat's little theorem, which says that for $p$ prime and $a$ coprime to $p$, $a^{p-1} \equiv 1 \pmod p$, so see if $2^{8222838654177922817725562880000000} \equiv 1 \pmod {8222838654177922817725562880000001}$  You can do this rather quickly by computer if you have the right package.  If this equivalence fails, you have a composite.  If it passes, check a few other small primes.  If it passes them all, you almost certainly have a prime.