Primality proof for n = 312289:
Take b = 2.
b^(n-1) mod n = 1.
3253 is prime. b^((n-1)/3253)-1 mod n = 257256, which is a unit, inverse 24151.
(3253) divides n-1.
(3253)^2 > n.
n is prime by Pocklington's theorem.