Implements isPrime to check if a number is prime in constant time