Example #1
0
    // 戻り値の長さは |a| + |b| - 1 となります。
    public static long[] Convolution(long[] a, long[] b)
    {
        if (a == null)
        {
            throw new ArgumentNullException(nameof(a));
        }
        if (b == null)
        {
            throw new ArgumentNullException(nameof(b));
        }

        var n   = a.Length + b.Length - 1;
        var ntt = new FNTT(n);

        var fa = ntt.Transform(a, false);
        var fb = ntt.Transform(b, false);

        for (int k = 0; k < fa.Length; ++k)
        {
            fa[k] = fa[k] * fb[k] % p;
        }
        var c = ntt.Transform(fa, true);

        if (n < c.Length)
        {
            Array.Resize(ref c, n);
        }
        return(c);
    }
        public void Transform_FNTT()
        {
            var ntt = new FNTT(n);

            Test(f => ntt.Transform(f, false), f => ntt.Transform(f, true));
        }