Last active
March 21, 2017 13:51
-
-
Save bruceoutdoors/6dbfaf44d6468627cd592229aa3b2fac to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
using namespace std; | |
typedef vector<int> ivec; | |
ivec polynomialMultiply(const ivec &a, const ivec &b) | |
{ | |
int N = 2 * a.size() - 1; | |
ivec c(N, 0); | |
for (int j = 0; j < N; ++j) { | |
int p = j >= a.size() ? j - a.size() + 1 : 0; | |
for (int k = p; k <= j - p; ++k) { | |
c[j] += a[k] * b[j - k]; | |
} | |
} | |
return c; | |
} | |
int main() | |
{ | |
ivec a = { 6, 7, -10, 9 }; | |
ivec b = { -2, 0, 4, -5 }; | |
ivec c = polynomialMultiply(a, b); | |
for (const auto &t : c) cout << t << ' '; | |
cout << endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment