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); } }
public DynamicModInt <T> Decrement(DynamicModInt <T> x) => -- x;
public DynamicModInt <T> Increment(DynamicModInt <T> x) => ++ x;
public DynamicModInt <T> Minus(DynamicModInt <T> x) => - x;
DynamicModInt <T> IDivisionOperator <DynamicModInt <T> > .Modulo(DynamicModInt <T> x, DynamicModInt <T> y) => throw new NotSupportedException();
public DynamicModInt <T> Divide(DynamicModInt <T> x, DynamicModInt <T> y) => x / y;
public DynamicModInt <T> Multiply(DynamicModInt <T> x, DynamicModInt <T> y) => x * y;
public DynamicModInt <T> Subtract(DynamicModInt <T> x, DynamicModInt <T> y) => x - y;
public DynamicModInt <T> Add(DynamicModInt <T> x, DynamicModInt <T> y) => x + y;
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); } }