bignum_1.py 355 B

123456789101112
  1. def xhash(coeff, exp):
  2. sign = 1
  3. if coeff < 0:
  4. sign = -1
  5. coeff = -coeff
  6. if exp >= 0:
  7. exp_hash = pow(10, exp, _PyHASH_MODULUS)
  8. else:
  9. exp_hash = pow(_PyHASH_10INV, -exp, _PyHASH_MODULUS)
  10. hash_ = coeff * exp_hash % _PyHASH_MODULUS
  11. ans = hash_ if sign == 1 else -hash_
  12. return -2 if ans == -1 else ans