Convolution

It calculates $(+,\times)$ convolution. Given two arrays $a_0, a_1, \cdots, a_{N - 1}$ and $b_0, b_1, \cdots, b_{M - 1}$, it calculates the array $c$ of length $N + M - 1$, defined by

$$c_i = \sum_{j = 0}^i a_j b_{i - j}$$

convolution

(1) vector<T> convolution<int m = 998244353>(vector<T> a, vector<T> b)
💻(2) vector<static_modint<m>> convolution<int m>(vector<static_modint<m>> a, vector<static_modint<m>> b)

It calculates the convolution in $\bmod m$. It returns an empty array if at least one of $a$ and $b$ are empty.

Constraints

Complexity

convolution_ll

vector<ll> convolution_ll(vector<ll> a, vector<ll> b)

It calculates the convolution. It returns an empty array if at least one of $a$ and $b$ are empty.

Constraints

Complexity

Examples

AC code of https://atcoder.jp/contests/practice2/tasks/practice2_f

include atcoder/header import atcoder/convolution import atcoder/modint let n, m = nextInt() a = newSeqWith(n, nextInt()) b = newSeqWith(m, nextInt()) let c = convolution[998244353, int](a, b) # or: c = convolution<998244353>(a, b) echo c.join(" ")

AC code of https://atcoder.jp/contests/practice2/tasks/practice2_f

include atcoder/header import atcoder/modint import atcoder/convolution type mint = modint998244353 let n, m = nextInt() a = newSeqWith(n, mint(nextInt())) b = newSeqWith(m, mint(nextInt())) c = convolution(a, b) echo c.join(" ")