def process(A, B, modulus, operation): zero = bigInt.bigInt("0") res = zero if (modulus < zero): print "Negative modulus!" return False, res if operation == '^': res = bigInt.pow(A, B, modulus) return True, res if (modulus > zero): A %= modulus B %= modulus if operation == '+': res = A + B elif operation == '-': res = A - B elif operation == '*': res = A * B elif operation == '/': if B == zero: print "Division by zero" return False, res res = A / B elif operation == '%': if (B == zero): print "Division by zero" return False, res res = A % B if (modulus > zero): res %= modulus while (res < zero): res += modulus return True, res
def noArguments(): print "Launched without parameters." print "Perform all kind of operations with entered numbers." print "Enter A:", a = bigInt.bigInt(raw_input()) print "Enter B:", b = bigInt.bigInt(raw_input()) print "A + B =", a, "+", b, "=", a + b print "A - B =", a, "-", b, "=", a - b print "A * B =", a, "*", b, "=", a * b if b != bigInt.bigInt("0"): print "A / B =", a, "/", b, "=", a / b print "A % B =", a, "%", b, "=", a % b else: print "Division by zero" print "Enter modulus for pow: ", mod = bigInt.bigInt(raw_input()) print "A ^ B mod N =", a, "^", b, "mod", mod, "=", bigInt.pow(a, b, mod) print "That's all"
def PowMod(A, B, M): return bigInt.pow(A, B, M)