commands → prime

prime(A)

The prime command tests whether an integer A is prime.

Examples

prime(2);
	1

prime(3*5);
	0

Algorithm

The algorithm uses Miller-Rabin tests which are probabilistic for large integers. For small integers the tests are deterministic.

References

The Miller-Rabin Test on Wikipedia
Koblitz, Neal. A Course in Number Theory and Cryptography. Springer, 1998.