コード例 #1
0
ファイル: ABC160_F.cs プロジェクト: sono8stream/AtPractice
        static void DFS3(int now, int parent,
                         List <int>[] graph, long[] res, int[] childs,
                         long[] pats, CaseCalculator calculator, long mask)
        {
            long pat = 1;

            if (parent == -1)
            {
                pat = pats[now];
            }
            else
            {
                long parentVal = (res[parent] * calculator.Inverse(
                                      calculator.Permutation(childs.Length - 1, childs[now] + 1))) % mask;
                parentVal = (parentVal * calculator.Permutation(
                                 childs[now] + 1, childs[now] + 1)) % mask;
                parentVal = (parentVal * calculator.Inverse(pats[now])) % mask;
                parentVal = (parentVal * calculator.Combination(
                                 childs.Length - 1, childs[now])) % mask;
                pat = (parentVal * pats[now]) % mask;
            }
            res[now] = pat;

            for (int i = 0; i < graph[now].Count; i++)
            {
                int to = graph[now][i];
                if (to == parent)
                {
                    continue;
                }

                DFS3(to, now, graph, res, childs, pats, calculator, mask);
            }
        }
コード例 #2
0
        static void Method(string[] args)
        {
            int  q          = ReadInt();
            long mask       = 1000003;
            var  calculator = new CaseCalculator(mask, mask + 100);

            for (int i = 0; i < q; i++)
            {
                long[] xdn = ReadLongs();
                long   x   = xdn[0];
                long   d   = xdn[1];
                long   n   = xdn[2];

                if (d == 0)
                {
                    WriteLine(calculator.Pow(x, n));
                }
                else
                {
                    long baseVal = calculator.Multi(x, calculator.Inverse(d));
                    if (baseVal + n - 1 >= mask)
                    {
                        WriteLine(0);
                    }
                    else
                    {
                        WriteLine(calculator.Multi(
                                      calculator.Permutation(baseVal + n - 1, n),
                                      calculator.Pow(d, n)));
                    }
                }
            }
        }
コード例 #3
0
ファイル: D.cs プロジェクト: sono8stream/AtPractice
        static void Method(string[] args)
        {
            int[] nm = ReadInts();
            long  n  = nm[0];
            long  m  = nm[1];

            long[] array = ReadLongs();
            long   sum   = array.Sum();

            if (m < sum)
            {
                WriteLine(0);
                return;
            }

            long mask       = 1000000000 + 7;
            var  calculator = new CaseCalculator(mask, sum + n);
            long res        = 1;

            for (long i = m + n; i > m + n - (sum + n); i--)
            {
                res *= i;
                res %= mask;
            }
            res *= calculator.Inverse(calculator.Permutation(sum + n, sum + n));
            res %= mask;
            WriteLine(res);
        }
コード例 #4
0
ファイル: D.cs プロジェクト: sono8stream/AtPractice
        static void Method(string[] args)
        {
            long[] nab  = ReadLongs();
            long   n    = nab[0];
            long   a    = nab[1];
            long   b    = nab[2];
            long   mask = 1000000000 + 7;

            long[] pows = new long[40];
            pows[0] = 2;
            for (int i = 1; i < pows.Length; i++)
            {
                pows[i]  = pows[i - 1] * pows[i - 1];
                pows[i] %= mask;
            }
            long all = 1;
            long tmp = 1;

            for (int i = 0; i < 40; i++)
            {
                if ((n / tmp) % 2 == 1)
                {
                    all *= pows[i];
                    all %= mask;
                }
                tmp *= 2;
            }
            all = (all - 1 + mask) % mask;

            CaseCalculator calculator = new CaseCalculator(mask, Max(a, b));
            long           nA         = 1;
            long           nB         = 1;

            for (long i = n; i >= n - a + 1; i--)
            {
                nA *= i;
                nA %= mask;
            }
            for (long i = n; i >= n - b + 1; i--)
            {
                nB *= i;
                nB %= mask;
            }
            all = (all - (nA * calculator.Inverse(calculator.Permutation(a, a))) % mask + mask) % mask;
            all = (all - (nB * calculator.Inverse(calculator.Permutation(b, b))) % mask + mask) % mask;
            WriteLine(all);
        }
コード例 #5
0
        static void Method(string[] args)
        {
            int[] nk = ReadInts();
            int   n  = nk[0];
            int   k  = nk[1];

            long[] array = ReadLongs();
            long   mask  = 998244353;

            var calculator = new CaseCalculator(mask, k + 5);

            long[,] pows = new long[k + 1, n];
            long[] pow2s = new long[k + 1];
            for (int i = 0; i <= k; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    if (i == 0)
                    {
                        pows[i, j] = 1;
                    }
                    else
                    {
                        pows[i, j]  = pows[i - 1, j] * array[j];
                        pows[i, j] %= mask;
                    }
                }

                if (i == 0)
                {
                    pow2s[i] = 1;
                }
                else
                {
                    pow2s[i]  = pow2s[i - 1] * 2;
                    pow2s[i] %= mask;
                }
            }

            long[] sums = new long[k + 1];
            for (int i = 0; i <= k; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    sums[i] += pows[i, j];
                    sums[i] %= mask;
                }
            }

            for (int i = 1; i <= k; i++)
            {
                long val = 0;
                for (int j = 0; j <= i; j++)
                {
                    long left  = sums[j] * calculator.Inverse(calculator.Permutation(j, j));
                    long right = sums[i - j] * calculator.Inverse(calculator.Permutation(i - j, i - j));
                    left  %= mask;
                    right %= mask;
                    val   += left * right;
                    val   %= mask;
                }
                val *= calculator.Permutation(i, i);
                val %= mask;
                long sames = pow2s[i] * sums[i];
                sames %= mask;
                val   += mask - sames;
                val   %= mask;
                val   *= calculator.Inverse(2);
                val   %= mask;

                WriteLine(val);
            }
        }