title: Fastest way of testing if a number is prime?
body: <p>I'm trying to get a fast way to determine if a number is prime using Python.</p>
  <p>I have two functions to do this. Both return either True or False.</p>
  <p>Function isPrime1 is very fast to return False is a number is not a prime. For example with a big number. But it is slow in testing True for big prime numbers.</p>
  <p>Function isPrime2 is faster in returning True for prime numbers. But if a number is big and it is not prime, it takes too long to return a value. First function works better with that.</p>
  <p>How can I come up with a solution that could quickly return False for a big number that is not prime and would work fast with a big number that is prime?</p>
  <pre><code>def isPrime1(number): #Works well with big numbers that are not prime
      state = True
      if number &lt;= 0:
          state = False
          return state
      else:          
          for i in range(2,number):
              if number % i == 0:
                  state = False
                  break
          return state
  
  def isPrime2(number): #Works well with big numbers that are prime   
      d = 2
      while d*d &lt;= number:
          while (number % d) == 0:            
              number //= d
          d += 1
      if number &gt; 1:       
          return True
      else:
          return False`
  </code></pre>