code: def mod_root(a, p):
      
      if a == 0:
          return 0
      if not mod_issquare(a, p):
          raise ValueError
      n = 2
      while mod_issquare(n, p):
          n += 1
      q = p - 1
      r = 0
      while not q.getbit(r):
          r += 1
      q = q >> r
      y = pow(n, q, p)
      h = q >> 1
      b = pow(a, h, p)
      x = (a * b) % p
      b = (b * x) % p
      while b != 1:
          h = (b * b) % p
          m = 1
          while h != 1:
              h = (h * h) % p
              m += 1
          h = gmpy.mpz(0)
          h = h.setbit(r - m - 1)
          t = pow(y, h, p)
          y = (t * t) % p
          r = m
          x = (x * t) % p
          b = (b * y) % p
      return x
docs: Return a root of `a' modulo p