CP Python LibraryGitHub

Arbitrary Mod Convolution

Calculates the convolution of two polynomials modulo a prime number pp.

Given two arrays A0,,An1A_0, \cdots, A_{n-1} and B0,,Bm1B_0, \cdots, B_{m-1} representing f(x)=i=0n1Aixif(x) = \displaystyle \sum_{i=0}^{n-1} A_i x^i and g(x)=i=0m1Bixig(x) = \displaystyle \sum_{i=0}^{m-1} B_i x^i respectively, the convolution f(x)g(x)=i=0n+m2Cixif(x)g(x) = \displaystyle \sum_{i=0}^{n+m-2} C_i x^i is defined as Ck=i=0kAiBkimodpC_k = \displaystyle \sum_{i=0}^{k} A_i B_{k-i} \mod p.

convolve

Arguments

Returns

Complexities

Code Test