diff options
| author | mzuenni <michi.zuendorf@gmail.com> | 2024-08-17 20:07:14 +0200 |
|---|---|---|
| committer | mzuenni <michi.zuendorf@gmail.com> | 2024-08-17 20:07:14 +0200 |
| commit | 915bbaea690d3d352b06d5a2660166de7fd9cd21 (patch) | |
| tree | cc9f271a6221fb79cbf3cfc06ef885d6b8f91d74 /content/math/transforms/seriesOperations.cpp | |
| parent | 55b0c65814beaac0e68b9c2b99bf42f9327ec61a (diff) | |
improve series operations
Diffstat (limited to 'content/math/transforms/seriesOperations.cpp')
| -rw-r--r-- | content/math/transforms/seriesOperations.cpp | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/content/math/transforms/seriesOperations.cpp b/content/math/transforms/seriesOperations.cpp index fc36f1e..b405698 100644 --- a/content/math/transforms/seriesOperations.cpp +++ b/content/math/transforms/seriesOperations.cpp @@ -24,10 +24,13 @@ vector<ll> poly_deriv(vector<ll> a) { } vector<ll> poly_integr(vector<ll> a) { - if (a.empty()) return {0}; - a.push_back(a.back() * powMod(sz(a), mod-2, mod) % mod); - for (int i = sz(a)-2; i > 0; i--) - a[i] = a[i-1] * powMod(i, mod-2, mod) % mod; + static vector<ll> inv = {0, 1}; + for (static int i = 2; i <= sz(a); i++) + inv.push_back(mod - mod / i * inv[mod % i] % mod); + + a.push_back(0); + for (int i = sz(a) - 1; i > 0; i--) + a[i] = a[i-1] * inv[i] % mod; a[0] = 0; return a; } @@ -35,8 +38,7 @@ vector<ll> poly_integr(vector<ll> a) { vector<ll> poly_log(vector<ll> a, int n) { a = mul(poly_deriv(a), poly_inv(a, n)); a.resize(n-1); - a = poly_integr(a); - return a; + return poly_integr(a); } vector<ll> poly_exp(vector<ll> a, int n) { |
