Skip to content

Commit 52c1fa2

Browse files
committed
interpolation + pow tests, adjust "magic"
1 parent 3a3ed82 commit 52c1fa2

File tree

4 files changed

+62
-2
lines changed

4 files changed

+62
-2
lines changed

cp-algo/math/common.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace cp_algo::math {
88
#else
99
const int maxn = 1 << 19;
1010
#endif
11-
const int magic = 250; // threshold for sizes to run the naive algo
11+
const int magic = 128; // threshold for sizes to run the naive algo
1212

1313
auto bpow(auto const& x, int64_t n, auto const& one, auto op) {
1414
if(n == 0) {

cp-algo/math/fft.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ namespace cp_algo::math::fft {
279279

280280
template<typename base>
281281
void mul(std::vector<base> &a, std::vector<base> const& b) {
282-
if(std::min(a.size(), b.size()) < 1) {
282+
if(std::min(a.size(), b.size()) < magic) {
283283
mul_slow(a, b);
284284
return;
285285
}

verify/poly/inter.test.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// @brief Polynomial Interpolation
2+
#define PROBLEM "https://judge.yosupo.jp/problem/polynomial_interpolation"
3+
#include "cp-algo/math/poly.hpp"
4+
#include <bits/stdc++.h>
5+
6+
using namespace std;
7+
using namespace cp_algo::math;
8+
9+
const int mod = 998244353;
10+
using base = modint<mod>;
11+
using polyn = poly_t<base>;
12+
13+
void solve() {
14+
int n;
15+
cin >> n;
16+
vector<base> x(n), y(n);
17+
copy_n(istream_iterator<base>(cin), n, begin(x));
18+
copy_n(istream_iterator<base>(cin), n, begin(y));
19+
polyn::inter(x, y).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+
}

verify/poly/pow.test.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// @brief Pow of Power Series
2+
#define PROBLEM "https://judge.yosupo.jp/problem/pow_of_formal_power_series"
3+
#include "cp-algo/math/poly.hpp"
4+
#include <bits/stdc++.h>
5+
6+
using namespace std;
7+
using namespace cp_algo::math;
8+
9+
const int mod = 998244353;
10+
using base = modint<mod>;
11+
using polyn = poly_t<base>;
12+
13+
void solve() {
14+
int n;
15+
int64_t m;
16+
cin >> n >> m;
17+
vector<base> a(n);
18+
copy_n(istream_iterator<base>(cin), n, begin(a));
19+
polyn(a).pow(m, 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)