Perhaps a way to approach the problem is:
For testing a prime 'p'
** Choose a number 'x' with a large number of distinct prime factors
** Represent all integers modulo x
Hence for x=12 (22 x 3) we have 12k+i for integers k and i=0,1,2,3,4,5,6,7,8,9,10,11
** Check division of 'p' by prime factors of 'x'
Hence for x=12:
prime factor 2 we can remove i=0,2,4,6,8,10
prime factor 3 we can remove i=3,6,9
Hence we are left to check all integers of the form 12k+i <= sqrt(p) for i=1,5,7,11
Severely reducing the number of division tests we have to make.