Program to generate an array having convolution of two given arrays | C ++ program for the above approach ; Function to generate a convolution array of two given arrays ; Stores the size of arrays ; Stores the final array ; Traverse the two given arrays ; Update the convolution array ; Print the convolution array c [ ] ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; constexpr int MOD = 998244353 ; void findConvolution ( const vector < int > & a , const vector < int > & b ) { int n = a . size ( ) , m = b . size ( ) ; vector < long long > c ( n + m - 1 ) ; for ( int i = 0 ; i < n ; ++ i ) { for ( int j = 0 ; j < m ; ++ j ) { c [ i + j ] += 1LL * ( a [ i ] * b [ j ] ) % MOD ; } } for ( int k = 0 ; k < c . size ( ) ; ++ k ) { c [ k ] %= MOD ; cout << c [ k ] << " ▁ " ; } } int main ( ) { vector < int > A = { 1 , 2 , 3 , 4 } ; vector < int > B = { 5 , 6 , 7 , 8 , 9 } ; findConvolution ( A , B ) ; return 0 ; }