예제 #1
0
        public IConvertible Solve()
        {
            int a = 0;
            int b = 0;

            if ((x + y) % 3 != 0)
            {
                return(0);
            }

            while (x + y >= 3)
            {
                if (x >= y)
                {
                    x -= 2;
                    y -= 1;
                    a++;
                }
                else
                {
                    y -= 2;
                    x -= 1;
                    b++;
                }
            }

            if (x != 0 || y != 0)
            {
                return(0);
            }

            return((int)Modular.Ncr(a + b, a));
        }
예제 #2
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));
            }
        }