# A primality test

Sebastian Garth wrote in sci.math (his original article is here) that an integer number n is prime iff

.

The double module makes it such a weird statement that I just had to check it... and it seems to be true!

Just write your prime candidate and click on the = sign:

The above program is useful only for n up to 2,000 , since computing the powers results in huge numbers and it runs ut of time. Now, if we compute the powers modulo n·(n+1)/2 from the beginning, we can save a lot of time; this other program can go up to n=250,000: