예제 #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);
        }
예제 #2
0
        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);
        }