예제 #1
0
        public static Modular Pow(Modular a, int n)
        {
            switch (n)
            {
            case 0:
                return(1);

            case 1:
                return(a);

            default:
                var p = Pow(a, n / 2);
                return(p * p * Pow(a, n % 2));
            }
        }
예제 #2
0
        public void Solve()
        {
            @in(out N);
            @in(out A);

            int l = -1;
            int r = -1;
            Dictionary <long, int> index = new Dictionary <long, int>();

            for (int i = 0; i < N + 1; i++)
            {
                if (index.ContainsKey(A[i]))
                {
                    l = index[A[i]];
                    r = (int)N - i;
                    break;
                }

                index.Add(A[i], i);
            }

            Console.WriteLine(N);
            for (int i = 2; i <= N + 1; i++)
            {
                Modular a = Modular.Ncr((int)N + 1, i);
                if (i == 2)
                {
                    a -= l + r;
                }
                else
                {
                    if (l > 0 && r > 0)
                    {
                        a -= Modular.Ncr(l + r, i - 1);
                    }
                    else if (l >= i - 1)
                    {
                        a -= Modular.Ncr(l, i);
                    }
                    else if (r >= i - 1)
                    {
                        a -= Modular.Ncr(r, i);
                    }
                }

                Console.WriteLine((int)a);
            }
        }