Пример #1
0
        public static void Solve()
        {
            var           N      = Scanner.Scan <int>();
            var           C      = Scanner.ScanEnumerable <int>().OrderByDescending(x => x).Select(x => (ModuloInteger)x).ToArray();
            ModuloInteger answer = 0;

            for (var i = 1; i <= N; i++)
            {
                answer += C[i - 1] * (i + 1);
            }
            answer *= ModuloInteger.Power(4, N - 1);

            Console.WriteLine(answer);
        }
Пример #2
0
        public static void Solve()
        {
            var L      = Scanner.Scan <string>();
            var answer = new ModuloInteger(0);
            var sum    = new ModuloInteger(1);

            for (var i = 0; i < L.Length; i++)
            {
                if (L[i] == '0')
                {
                    continue;
                }
                answer += sum * ModuloInteger.Power(3, L.Length - i - 1);
                sum    *= 2;
            }
            answer += sum;
            Console.WriteLine(answer);
        }
        public void Modulo1Test()
        {
            ModuloInteger.Modulo = 1;
            for (var i = 0; i < 100; i++)
            {
                for (var j = 0; j < 100; j++)
                {
                    Assert.That((i * (ModuloInteger)j).Value, Is.Zero);
                }
            }

            ModuloInteger l = 1234;
            ModuloInteger r = 5678;

            Assert.That((l + r).Value, Is.Zero);
            Assert.That((l - r).Value, Is.Zero);
            Assert.That((l * r).Value, Is.Zero);
            Assert.That(l.Power(r.Value).Value, Is.Zero);
            Assert.That(l.Inverse().Value, Is.Zero);
        }
 public void PowerTest([Values(11, 12, 998244353, 1000000007, 1000000008)] int modulo)
 {
     ModuloInteger.Modulo = modulo;
     for (var i = 1; i < Math.Min(modulo, 1000); i++)
     {
         var expected = 1L;
         var x        = ModuloInteger.Power(i, 0);
         var y        = new ModuloInteger(i).Power(0);
         Assert.That(ModuloInteger.Power(i, 0).Value, Is.EqualTo(1));
         Assert.That(x, Is.EqualTo(y));
         for (var j = 1; j <= 100; j++)
         {
             expected = expected * (i % modulo) % modulo;
             if (expected < 0)
             {
                 expected += modulo;
             }
             x = ModuloInteger.Power(i, j);
             y = new ModuloInteger(i).Power(j);
             Assert.That(x.Value, Is.EqualTo(expected));
             Assert.That(x, Is.EqualTo(y));
         }
     }
 }
Пример #5
0
        public static void Solve()
        {
            var K = Scanner.Scan <int>();
            var S = Scanner.Scan <string>();
            var N = S.Length;

            var max   = K + N + 1;
            var facts = new ModuloInteger[max];

            facts[0] = 1;
            for (var i = 1; i < max; i++)
            {
                facts[i] = facts[i - 1] * i;
            }

            var factInvs = new ModuloInteger[max];

            factInvs[max - 1] = facts[max - 1].Inverse();
            for (var i = max - 2; i >= 1; i--)
            {
                factInvs[i] = factInvs[i + 1] * (i + 1);
            }
            factInvs[0] = 1;

            ModuloInteger answer = 0;

            ModuloInteger Combination(int n, int r) => facts[n] * factInvs[r] * factInvs[n - r];

            for (var i = 0; i <= K; i++)
            {
                ModuloInteger comb = Combination(N + K - i - 1, N - 1);
                comb   *= (ModuloInteger.Power(25, K - i) * ModuloInteger.Power(26, i));
                answer += comb;
            }
            Console.WriteLine(answer.Value);
        }