borrow prime function from projecteuler