Extract isPrime function