Skip to content

Commit 2583069

Browse files
committed
Fixes + log test
1 parent dfebb6c commit 2583069

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

cp-algo/math/poly.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ namespace cp_algo::math {
167167

168168
poly_t log(size_t n) const { // calculate log p(x) mod x^n
169169
assert(a[0] == T(1));
170-
return (deriv().mod_xk(n) * inv(n)).integr().mod_xk(n);
170+
return (mod_xk(n).deriv() * inv(n)).mod_xk(n - 1).integr();
171171
}
172172

173173
poly_t exp(size_t n) const { // calculate exp p(x) mod x^n
@@ -547,6 +547,7 @@ namespace cp_algo::math {
547547

548548
// Return {P0, P1}, where P(x) = P0(x) + xP1(x)
549549
std::array<poly_t, 2> bisect(size_t n) const {
550+
n = std::min(n, size(a));
550551
std::deque<T> res[2];
551552
for(size_t i = 0; i < n; i++) {
552553
res[i % 2].push_back(a[i]);

cp-algo/math/poly/impl/div.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,9 @@ namespace cp_algo::math::poly::impl {
111111
inv_inplace(qq, (n + 1) / 2);
112112
auto qqf = fft::dft<base>(qq.a, N);
113113

114-
auto A = q0f * qqf;
115-
auto B = q1f * qqf;
114+
std::deque<base> A((n + 1) / 2), B((n + 1) / 2);
115+
q0f.mul(fft::dft<base>(qqf), A, (n + 1) / 2);
116+
q1f.mul(qqf, B, (n + 1) / 2);
116117
p.a.resize(n + 1);
117118
for(size_t i = 0; i < n; i += 2) {
118119
p.a[i] = A[i / 2];

verify/poly/log.test.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// @brief Log of Power Series
2+
#define PROBLEM "https://judge.yosupo.jp/problem/log_of_formal_power_series"
3+
#pragma GCC optimize("Ofast,unroll-loops")
4+
#include "cp-algo/math/poly.hpp"
5+
#include <bits/stdc++.h>
6+
7+
using namespace std;
8+
using namespace cp_algo::math;
9+
10+
const int mod = 998244353;
11+
using base = modint<mod>;
12+
using polyn = poly_t<base>;
13+
14+
void solve() {
15+
int n;
16+
cin >> n;
17+
vector<base> a(n);
18+
copy_n(istream_iterator<base>(cin), n, begin(a));
19+
polyn(a).log(n).print(n);
20+
}
21+
22+
signed main() {
23+
//freopen("input.txt", "r", stdin);
24+
ios::sync_with_stdio(0);
25+
cin.tie(0);
26+
int t = 1;
27+
while(t--) {
28+
solve();
29+
}
30+
}

0 commit comments

Comments
 (0)