コード例 #1
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)));
                    }
                }
            }
        }
コード例 #2
0
ファイル: ARC102_E.cs プロジェクト: sono8stream/AtPractice
        static void Method(string[] args)
        {
            long[] kn   = ReadLongs();
            long   k    = kn[0];
            long   n    = kn[1];
            long   mask = 998244353;

            CaseCalculator calculator = new CaseCalculator(mask, n + k - 1);

            long allPat = calculator.Combination(n + k - 1, n);

            long[] res = new long[2 * k - 1];

            long prevPats = 0;

            for (long val = 2; val <= k + 1; val++)
            {
                long pats = Min(val - 2, 2 * k - val) / 2 + 1;
                if (pats == prevPats)
                {
                    res[val - 2]     = res[val - 3];
                    res[2 * k - val] = res[val - 3];
                    continue;
                }

                long seqCnt = Min(pats, n / 2);
                long resTmp = allPat;
                for (long i = 1; i <= seqCnt; i++)
                {
                    long tmp = calculator.Combination(pats, i);
                    tmp = calculator.Multi(tmp,
                                           calculator.Combination(k - 1 + n - i * 2, k - 1));
                    if (i % 2 == 1)
                    {
                        resTmp += mask - tmp;
                    }
                    else
                    {
                        resTmp += tmp;
                    }
                    resTmp %= mask;
                }

                res[val - 2]     = resTmp;
                res[2 * k - val] = resTmp;
                prevPats         = pats;
            }

            for (int i = 0; i < 2 * k - 1; i++)
            {
                WriteLine(res[i]);
            }
        }
コード例 #3
0
ファイル: E.cs プロジェクト: sono8stream/AtPractice
        static void Method(string[] args)
        {
            long[]         nk         = ReadLongs();
            long           n          = nk[0];
            long           k          = nk[1];
            long           mask       = 1000000000 + 7;
            CaseCalculator calculator = new CaseCalculator(mask, n * 2);
            long           res        = 1;

            for (long i = 1; i <= Min(n, k); i++)
            {
                long tmp = calculator.Combination(n, i);
                tmp  = calculator.Multi(tmp, calculator.Combination(n - 1, i));
                res += tmp;
                res %= mask;
            }
            WriteLine(res);
        }
コード例 #4
0
ファイル: G.cs プロジェクト: sono8stream/AtPractice
        static void Method(string[] args)
        {
            long[] nk = ReadLongs();
            long n = nk[0];
            long k = nk[1];
            string t = Read();
            long equals = 0;
            long notEquals = 0;
            for (int i = 0; i < t.Length / 2; i++)
            {
                if (t[i] == t[(int)n - i - 1]) equals++;
                else notEquals++;
            }
            long mask = 1000000000 + 7;
            long[] equalPats = new long[equals+1];
            long[] notEqualPats = new long[notEquals+1];
            CaseCalculator calculator = new CaseCalculator(mask, n);
            long pow25 = 1;
            for(long i = 0; i <= equals; i++)
            {
                equalPats[i] = calculator.Combination(equals, i);
                equalPats[i] = calculator.Multi(equalPats[i], pow25);
                pow25 *= 25;
                pow25 %= mask;
                if (i > 0)
                {
                    equalPats[i] += equalPats[i - 1];
                    equalPats[i] %= mask;
                }
            }
            long[] twoPows = new long[notEquals + 1];
            twoPows[0] = 1;
            for(long i = 1; i <= notEquals; i++)
            {
                twoPows[i] = twoPows[i - 1] * 2;
                twoPows[i] %= mask;
            }
            long pow24 = 1;
            for(long i = 0; i <= notEquals; i++)
            {
                notEqualPats[i] = calculator.Multi(
                    calculator.Combination(notEquals, i), twoPows[notEquals - i]);
                notEqualPats[i] = calculator.Multi(notEqualPats[i], pow24);
                pow24 *= 24;
                pow24 %= mask;
            }
            /*
            long[] notEqualSums = new long[notEquals + 1];
            for (long i = 0; i <= notEquals; i++)
            {
                notEqualSums[i] = notEqualPats[i];
                if (i > 0) notEqualSums[i] += notEqualSums[i - 1];
                notEqualSums[i] %= mask;
            }
            */

            long res = 0;
            bool haveCenter = n % 2 == 1;
            for (long i = 0; i <= notEquals; i++)
            {
                long remain = k - notEquals - i;
                if (remain < 0) continue;

                if (!(notEquals == 0 && remain == 1))
                {
                    res += calculator.Multi(notEqualPats[i],
                        equalPats[Min(equals, remain / 2)]);
                }

                if (remain > 0 && haveCenter)
                {
                    long tmp = calculator.Multi(notEqualPats[i],
                        equalPats[Min(equals,(remain - 1) / 2)]);
                    tmp = calculator.Multi(tmp, 25);
                    res += tmp;
                }
                res %= mask;
            }
            WriteLine(res);
        }