Exemple #1
0
        BigInteger mul_inv(BigInteger e, BigInteger n)
        {
            BigInteger b0 = n, t, q;
            BigInteger x0 = 0, x1 = 1;

            if (n == 1)
            {
                return(1);
            }
            while (e > 1)
            {
                q = e / n;
                t = n; n = e % n; e = t;
                t = x0; x0 = x1 - q * x0; x1 = t;
            }
            if (x1 < 0)
            {
                x1 += b0;
            }
            return(x1);
        }