modified isprime function