Implement the test for primality using Fermat's last theorem.