File tree Expand file tree Collapse file tree 2 files changed +81
-0
lines changed Expand file tree Collapse file tree 2 files changed +81
-0
lines changed Original file line number Diff line number Diff line change
1
+ // @brief Kth term of Linearly Recurrent Sequence
2
+ #define PROBLEM " https://judge.yosupo.jp/problem/kth_term_of_linearly_recurrent_sequence"
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
+ int64_t d, k;
16
+ cin >> d >> k;
17
+ vector<base> a (d), c (d);
18
+ copy_n (istream_iterator<base>(cin), d, begin (a));
19
+ copy_n (istream_iterator<base>(cin), d, begin (c));
20
+ polyn Q = polyn (1 ) - polyn (c).mul_xk (1 );
21
+ polyn P = (polyn (a) * Q).mod_xk (d);
22
+ cout << polyn::kth_rec (P, Q, k) << endl;
23
+ }
24
+
25
+ signed main () {
26
+ // freopen("input.txt", "r", stdin);
27
+ ios::sync_with_stdio (0 );
28
+ cin.tie (0 );
29
+ int t = 1 ;
30
+ while (t--) {
31
+ solve ();
32
+ }
33
+ }
Original file line number Diff line number Diff line change
1
+ // @brief Product of Polynomial Sequence
2
+ #define PROBLEM " https://judge.yosupo.jp/problem/product_of_polynomial_sequence"
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<polyn> polys (N);
18
+ multiset<polyn, decltype ([](polyn const & a, polyn const & b){
19
+ return a.deg () < b.deg ();
20
+ })> que = {polyn (1 )};
21
+ int D = 0 ;
22
+ for (int i = 0 ; i < N; i++) {
23
+ int d;
24
+ cin >> d;
25
+ D += d;
26
+ vector<base> a (d + 1 );
27
+ copy_n (istream_iterator<base>(cin), d + 1 , begin (a));
28
+ que.insert (polyn (a));
29
+ }
30
+ while (que.size () > 1 ) {
31
+ auto A = *begin (que);
32
+ que.erase (begin (que));
33
+ auto B = *begin (que);
34
+ que.erase (begin (que));
35
+ que.insert (A * B);
36
+ }
37
+ begin (que)->print (D + 1 );
38
+ }
39
+
40
+ signed main () {
41
+ // freopen("input.txt", "r", stdin);
42
+ ios::sync_with_stdio (0 );
43
+ cin.tie (0 );
44
+ int t = 1 ;
45
+ while (t--) {
46
+ solve ();
47
+ }
48
+ }
You can’t perform that action at this time.
0 commit comments