Пример #1
0
        public void Memory()
        {
            DynamicModInt <MemoryID> .Mod = 101;

            var mt = MTRandom.Create();

            for (int n = 0; n < 100; n++)
            {
                var arr      = new DynamicModInt <MemoryID> [n];
                var expected = new uint[n];
                for (int i = 0; i < n; i++)
                {
                    var v = mt.NextUInt();
                    arr[i]      = v;
                    expected[i] = v % 101;
                }
                MemoryMarshal.Cast <DynamicModInt <MemoryID>, uint>(arr).ToArray()
                .Should().Equal(expected);
            }
        }
Пример #2
0
 public DynamicModInt <T> Decrement(DynamicModInt <T> x) => -- x;
Пример #3
0
 public DynamicModInt <T> Increment(DynamicModInt <T> x) => ++ x;
Пример #4
0
 public DynamicModInt <T> Minus(DynamicModInt <T> x) => - x;
Пример #5
0
 DynamicModInt <T> IDivisionOperator <DynamicModInt <T> > .Modulo(DynamicModInt <T> x, DynamicModInt <T> y) => throw new NotSupportedException();
Пример #6
0
 public DynamicModInt <T> Divide(DynamicModInt <T> x, DynamicModInt <T> y) => x / y;
Пример #7
0
 public DynamicModInt <T> Multiply(DynamicModInt <T> x, DynamicModInt <T> y) => x * y;
Пример #8
0
 public DynamicModInt <T> Subtract(DynamicModInt <T> x, DynamicModInt <T> y) => x - y;
Пример #9
0
 public DynamicModInt <T> Add(DynamicModInt <T> x, DynamicModInt <T> y) => x + y;
Пример #10
0
        public void Inv()
        {
            for (int i = 1; i < 10; i++)
            {
                int x = new StaticModInt <InvID11>(i).Inv().Value;
                ((long)x * i % 11).Should().Be(1);
            }


            for (int i = 1; i < 12; i++)
            {
                if (Gcd(i, 12) != 1)
                {
                    continue;
                }
                int x = new StaticModInt <InvID12>(i).Inv().Value;
                ((long)x * i % 12).Should().Be(1);
            }

            for (int i = 1; i < 100000; i++)
            {
                int x = new StaticModInt <InvID1000000007>(i).Inv().Value;
                ((long)x * i % 1000000007).Should().Be(1);
            }

            for (int i = 1; i < 100000; i++)
            {
                if (Gcd(i, 1000000008) != 1)
                {
                    continue;
                }
                int x = new StaticModInt <InvID1000000008>(i).Inv().Value;
                ((long)x * i % 1000000008).Should().Be(1);
            }

            for (int i = 1; i < 100000; i++)
            {
                int x = new StaticModInt <InvID998244353>(i).Inv().Value;
                ((long)x * i % 998244353).Should().Be(1);
            }

            DynamicModInt <InvID998244353> .Mod = 998244353;
            for (int i = 1; i < 100000; i++)
            {
                int x = new DynamicModInt <InvID998244353>(i).Inv().Value;
                x.Should().BeGreaterOrEqualTo(0);
                x.Should().BeLessOrEqualTo(998244353 - 1);
                ((long)x * i % 998244353).Should().Be(1);
            }


            DynamicModInt <InvID1000000008> .Mod = 1000000008;
            for (int i = 1; i < 100000; i++)
            {
                if (Gcd(i, 1000000008) != 1)
                {
                    continue;
                }
                int x = new DynamicModInt <InvID1000000008>(i).Inv().Value;
                ((long)x * i % 1000000008).Should().Be(1);
            }
        }