Beispiel #1
0
        /// <summary>
        /// nが大きくてkが小さいときに使える。
        /// </summary>
        /// <param name="n"></param>
        /// <param name="k"></param>
        /// <returns></returns>
        static Mint nCk(long n, long k)
        {
            Mint x = 1;
            Mint y = 1;

            for (int i = 0; i < k; i++)
            {
                x *= n - i;
                y *= i + 1;
            }
            return(x / y);
        }
Beispiel #2
0
        public static Mint Pow(Mint a, long n)
        {
            if (n == 0)
            {
                return(new Mint(1));
            }
            Mint b = Pow(a, n >> 1);

            b *= b;
            if ((n & 1) == 1)
            {
                b *= a;
            }
            return(b);
        }
Beispiel #3
0
        public static void Abc156_D()
        {
            long n = rl;
            long a = rl;
            long b = rl;

            var total = Mint.Pow(2, n) - 1;
            var a1    = nCk(n, a);

            total -= a1;
            var b1 = nCk(n, b);

            total -= b1;

            Console.WriteLine(total);
        }
Beispiel #4
0
        public static Mint Inv(Mint n)
        {
            long a = n.Value;
            long b = MOD;

            long x = 1;
            long u = 0;

            while (b != 0)
            {
                long k  = a / b;
                long _x = u;
                u = x - k * u;
                x = _x;

                long _a = a;
                a = b;
                b = _a - (k * b);
            }

            return(new Mint(x));
        }