Exemple #1
0
        public static ulong BinaryMod2(ulong b, ulong e, ulong m)
        {
            if (e == 0)
            {
                return(1);
            }
            ulong r = 1;

            for (; e > 0; e >>= 1)
            {
                if ((e & 1) == 1)
                {
                    r = Mul.Mod(r, b, m);
                }
                b = Mul.Mod(b, b, m);
            }
            return(r);
        }