File tree Expand file tree Collapse file tree 3 files changed +35
-3
lines changed Expand file tree Collapse file tree 3 files changed +35
-3
lines changed Original file line number Diff line number Diff line change @@ -167,7 +167,7 @@ namespace cp_algo::math {
167
167
168
168
poly_t log (size_t n) const { // calculate log p(x) mod x^n
169
169
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 ( );
171
171
}
172
172
173
173
poly_t exp (size_t n) const { // calculate exp p(x) mod x^n
@@ -547,6 +547,7 @@ namespace cp_algo::math {
547
547
548
548
// Return {P0, P1}, where P(x) = P0(x) + xP1(x)
549
549
std::array<poly_t , 2 > bisect (size_t n) const {
550
+ n = std::min (n, size (a));
550
551
std::deque<T> res[2 ];
551
552
for (size_t i = 0 ; i < n; i++) {
552
553
res[i % 2 ].push_back (a[i]);
Original file line number Diff line number Diff line change @@ -111,8 +111,9 @@ namespace cp_algo::math::poly::impl {
111
111
inv_inplace (qq, (n + 1 ) / 2 );
112
112
auto qqf = fft::dft<base>(qq.a , N);
113
113
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 );
116
117
p.a .resize (n + 1 );
117
118
for (size_t i = 0 ; i < n; i += 2 ) {
118
119
p.a [i] = A[i / 2 ];
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments