Example #1
0
    static void Main()
    {
        var(n, m, k) = Read3();

        var ncrs = MNcrs(n - 1);

        MInt r = 0;

        for (int i = n - 1 - k; i < n; i++)
        {
            r += ncrs[i] * m *MInt.MPow(m - 1, i);
        }
        Console.WriteLine(r);
    }
Example #2
0
    static void Main()
    {
        var h = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        int n = h[0], k = h[1];

        MInt r = 0, c = 1;

        for (int i = 0; i < k; i++)
        {
            r += c * MInt.MPow(k - i, n);
            c *= -(k - i);
            c /= i + 1;
        }
        Console.WriteLine(r);
    }
Example #3
0
    static void Main()
    {
        var h = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        int n = h[0], k = h[1];

        var f = new MInt[k + 1];
        var t = new MInt[k + 1];

        f[0] = 1;
        t[0] = 1;
        for (int i = 1; i <= k; ++i)
        {
            f[i] = f[i - 1] / i;
            t[i] = t[i - 1] + f[i] * (i % 2 == 0 ? 1 : -1);
        }

        MInt r = 0;

        for (int i = 1; i <= k; ++i)
        {
            r += MInt.MPow(i, n) * f[i] * t[k - i];
        }
        Console.WriteLine(r);
    }