public static BigInt pow(BigInt a, BigInt n) { if (n.isZero()) { return(BigInt.valueOf(1)); } BigInt c = mod(n, valueOf(2)); if (equal(valueOf(1), c)) { return(multiply(pow(a, subtract(n, valueOf(1))), a)); } else { BigInt b = pow(a, divide(n, valueOf(2))); return(multiply(b, b)); } }