Primality proof for n = 3331:
Take b = 2.
b^(n-1) mod n = 1.
37 is prime.
b^((n-1)/37)-1 mod n = 2994, which is a unit, inverse 2135.
2 is prime.
b^((n-1)/2)-1 mod n = 3329, which is a unit, inverse 1665.
(2 * 37) divides n-1.
(2 * 37)^2 > n.
n is prime by Pocklington's theorem.