0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-08 12:58:48 +00:00

P4512 【模板】多项式除法

https://www.luogu.com.cn/record/96412945
This commit is contained in:
Baoshuo Ren 2022-12-03 15:59:20 +08:00
parent c1d49f8976
commit d73cc89f59
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A

View File

@ -138,26 +138,10 @@ class Poly : public std::vector<long long> {
return b;
}
} poly;
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
Poly f(n + 1), g(m + 1);
for (int i = 0; i <= n; i++) {
cin >> f[i];
}
for (int i = 0; i <= m; i++) {
cin >> g[i];
}
static std::pair<Poly, Poly> div(Poly f, Poly g) {
int n = f.size() - 1,
m = g.size() - 1;
Poly rev_f{f}, rev_g{g};
std::reverse(rev_f.begin(), rev_f.end());
@ -178,6 +162,32 @@ int main() {
r[i] = ((f[i] - g[i]) % mod + mod) % mod;
}
return {q, r};
}
} poly;
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
Poly f(n + 1), g(m + 1);
for (int i = 0; i <= n; i++) {
cin >> f[i];
}
for (int i = 0; i <= m; i++) {
cin >> g[i];
}
auto res = Poly::div(f, g);
Poly q = res.first,
r = res.second;
for (int i = 0; i <= n - m; i++) {
cout << q[i] << ' ';
}