На
одном известном ресурсе говорится, что
Цитата:
The prime numbers can be defined as consisting of:
-2, the smallest prime;
-each positive integer which is not evenly divisible by any of the primes smaller than itself.
The integer 2 is our base case; checking the primality of any larger integer X requires us to know the primality of every integer between X and 2, but each such integer is closer to our base case of 2 than X is.
Думаю, можно алгоритм основывать на этом.