Exemple #1
0
        private static StaticModInt <T>[] CalcurateSumE()
        {
            int g    = InternalMath.PrimitiveRoot((int)default(T).Mod);
            int cnt2 = InternalBit.BSF(default(T).Mod - 1);
            var e    = new StaticModInt <T>(g).Pow((default(T).Mod - 1) >> cnt2);
            var ie   = e.Inv();

            var sumE = new StaticModInt <T> [cnt2 - 2];

            // es[i]^(2^(2+i)) == 1
            Span <StaticModInt <T> > es  = stackalloc StaticModInt <T> [cnt2 - 1];
            Span <StaticModInt <T> > ies = stackalloc StaticModInt <T> [cnt2 - 1];

            for (int i = es.Length - 1; i >= 0; i--)
            {
                // e^(2^(2+i)) == 1
                es[i]  = e;
                ies[i] = ie;
                e     *= e;
                ie    *= ie;
            }

            var now = StaticModInt <T> .Raw(1);

            for (int i = 0; i < sumE.Length; i++)
            {
                sumE[i] = es[i] * now;
                now    *= ies[i];
            }

            return(sumE);
        }
 public void PrimitiveRootTemplateTest()
 {
     MathUtil.IsPrimitiveRoot(2, InternalMath.PrimitiveRoot <Mod2>()).Should().BeTrue();
     MathUtil.IsPrimitiveRoot(3, InternalMath.PrimitiveRoot <Mod3>()).Should().BeTrue();
     MathUtil.IsPrimitiveRoot(5, InternalMath.PrimitiveRoot <Mod5>()).Should().BeTrue();
     MathUtil.IsPrimitiveRoot(7, InternalMath.PrimitiveRoot <Mod7>()).Should().BeTrue();
     MathUtil.IsPrimitiveRoot(11, InternalMath.PrimitiveRoot <Mod11>()).Should().BeTrue();
     MathUtil.IsPrimitiveRoot(998244353, InternalMath.PrimitiveRoot <Mod998244353>()).Should().BeTrue();
     MathUtil.IsPrimitiveRoot(1000000007, InternalMath.PrimitiveRoot <Mod1000000007>()).Should().BeTrue();
     MathUtil.IsPrimitiveRoot(469762049, InternalMath.PrimitiveRoot <Mod469762049>()).Should().BeTrue();
     MathUtil.IsPrimitiveRoot(167772161, InternalMath.PrimitiveRoot <Mod167772161>()).Should().BeTrue();
     MathUtil.IsPrimitiveRoot(754974721, InternalMath.PrimitiveRoot <Mod754974721>()).Should().BeTrue();
     MathUtil.IsPrimitiveRoot(324013369, InternalMath.PrimitiveRoot <Mod324013369>()).Should().BeTrue();
     MathUtil.IsPrimitiveRoot(831143041, InternalMath.PrimitiveRoot <Mod831143041>()).Should().BeTrue();
     MathUtil.IsPrimitiveRoot(1685283601, InternalMath.PrimitiveRoot <Mod1685283601>()).Should().BeTrue();
 }
        private static StaticModInt <T>[] CalcurateSumIE()
        {
            int g    = InternalMath.PrimitiveRoot <T>();
            int cnt2 = InternalBit.BSF(default(T).Mod - 1);
            var e    = new StaticModInt <T>(g).Pow((default(T).Mod - 1) >> cnt2);
            var ie   = e.Inv();

            var sumIE = new StaticModInt <T> [30];

            // es[i]^(2^(2+i)) == 1
            Span <StaticModInt <T> > es =
#if !NETCOREAPP3_0_OR_GREATER
                new
#else
                stackalloc
#endif
                StaticModInt <T> [cnt2 - 1];
            Span <StaticModInt <T> > ies =
#if !NETCOREAPP3_0_OR_GREATER
                new
#else
                stackalloc
#endif
                StaticModInt <T> [cnt2 - 1];

            for (int i = es.Length - 1; i >= 0; i--)
            {
                // e^(2^(2+i)) == 1
                es[i]  = e;
                ies[i] = ie;
                e     *= e;
                ie    *= ie;
            }

            var now = StaticModInt <T> .Raw(1);

            for (int i = 0; i <= cnt2 - 2; i++)
            {
                sumIE[i] = ies[i] * now;
                now     *= es[i];
            }

            return(sumIE);
        }