File tree Expand file tree Collapse file tree 2 files changed +19
-18
lines changed Expand file tree Collapse file tree 2 files changed +19
-18
lines changed Original file line number Diff line number Diff line change 2
2
#define CP_ALGO_LINALG_FROBENIUS_HPP
3
3
#include " matrix.hpp"
4
4
#include " ../algebra/poly.hpp"
5
+ #include < algorithm>
5
6
#include < vector>
6
7
namespace cp_algo ::linalg {
7
8
enum frobenius_mode {blocks, full};
@@ -72,5 +73,23 @@ namespace cp_algo::linalg {
72
73
return charps;
73
74
}
74
75
}
76
+
77
+ template <typename base>
78
+ auto frobenius_pow (matrix<base> A, uint64_t k) {
79
+ using polyn = algebra::poly_t <base>;
80
+ auto [T, Tinv, charps] = frobenius_form<full>(A);
81
+ std::vector<matrix<base>> blocks;
82
+ for (auto charp: charps) {
83
+ matrix<base> block (charp.deg ());
84
+ auto xk = polyn::xk (1 ).powmod (k, charp);
85
+ for (size_t i = 0 ; i < block.n (); i++) {
86
+ std::ranges::copy (xk.a , begin (block[i]));
87
+ xk = xk.mul_xk (1 ) % charp;
88
+ }
89
+ blocks.push_back (block);
90
+ }
91
+ auto S = matrix<base>::block_diagonal (blocks);
92
+ return Tinv * S * T;
93
+ }
75
94
};
76
95
#endif // CP_ALGO_LINALG_FROBENIUS_HPP
Original file line number Diff line number Diff line change @@ -13,24 +13,6 @@ const int mod = 998244353;
13
13
using base = modular<mod>;
14
14
using polyn = poly_t <base>;
15
15
16
- template <typename base>
17
- auto frobenius_pow (matrix<base> A, uint64_t k) {
18
- using polyn = poly_t <base>;
19
- auto [T, Tinv, charps] = frobenius_form<full>(A);
20
- vector<matrix<base>> blocks;
21
- for (auto charp: charps) {
22
- matrix<base> block (charp.deg ());
23
- auto xk = polyn::xk (1 ).powmod (k, charp);
24
- for (size_t i = 0 ; i < block.n (); i++) {
25
- ranges::copy (xk.a , begin (block[i]));
26
- xk = xk.mul_xk (1 ) % charp;
27
- }
28
- blocks.push_back (block);
29
- }
30
- auto S = matrix<base>::block_diagonal (blocks);
31
- return Tinv * S * T;
32
- }
33
-
34
16
void solve () {
35
17
size_t n;
36
18
uint64_t k;
You can’t perform that action at this time.
0 commit comments