public static final long pow(long x, long n) throws Exception {
        if(n < 0)  return div (1, pow (x, (0 - n)));
        long r = 1;
        while (n != 0) {
            if ((n & 1L) != 0) r = mul(r, x);
            n >>= 1;
            x = mul(x, x);
        }
        return r;
    }