code: def is_prime(n, k=64):
      
      if n == 2:
          return True
      if n < 2 or n % 2 == 0:
          return False
      for i in range(3, 2048):  # performace optimisation
          if n % i == 0:
              return False
      s = 0
      d = n - 1
      while True:
          q, r = divmod(d, 2)
          if r == 1:
              break
          s += 1
          d = q
      for i in range(k):
          a = random.randint(2, n - 1)
          if check_candidate(a, d, n, s):
              return False
      return True
docs: Test whether n is prime probabilisticly.
  
      This uses the Miller-Rabin primality test. If n is composite,
      then this test will declare it to be probably prime with a
      probability of at most 4**-k.
  
      To be on the safe side, a value of k=64 for integers up to
      3072 bits is recommended (error probability = 2**-128). If
      the function is used for RSA or DSA, NIST recommends some
      values in FIPS PUB 186-3:
  
      <http://csrc.nist.gov/publications/fips/fips186-3/fips_186-3.pdf>
  
      Do not use this function for small numbers.