#include #include #include using namespace std; #include #include using mint = atcoder::modint998244353; template struct acl_fac { std::vector facs, facinvs; acl_fac(int N) { assert(-1 <= N and N < modint::mod()); facs.resize(N + 1, 1); for (int i = 1; i <= N; i++) facs[i] = facs[i - 1] * i; facinvs.assign(N + 1, facs.back().inv()); for (int i = N; i > 0; i--) facinvs[i - 1] = facinvs[i] * i; } modint ncr(int n, int r) const { if (n < 0 or r < 0 or n < r) return 0; return facs[n] * facinvs[r] * facinvs[n - r]; } modint operator[](int i) const { return facs[i]; } modint finv(int i) const { return facinvs[i]; } }; acl_fac fac(1000000); // https://hitonanode.github.io/cplib-cpp/formal_power_series/coeff_of_rational_function.hpp // Calculate [x^N](num(x) / den(x)) // - Coplexity: O(LlgLlgN) ( L = size(num) + size(den) ) // - Reference: `Bostan–Mori algorithm` template Tp coefficient_of_rational_function(long long N, std::vector num, std::vector den) { assert(N >= 0); while (den.size() and den.back() == 0) den.pop_back(); assert(den.size()); int h = 0; while (den[h] == 0) h++; N += h; den.erase(den.begin(), den.begin() + h); if (den.size() == 1) return N < int(num.size()) ? num[N] / den[0] : 0; while (N) { std::vector g = den; for (size_t i = 1; i < g.size(); i += 2) { g[i] = -g[i]; } auto conv_num_g = atcoder::convolution(num, g); num.resize((conv_num_g.size() + 1 - (N & 1)) / 2); for (size_t i = 0; i < num.size(); i++) { num[i] = conv_num_g[i * 2 + (N & 1)]; } auto conv_den_g = atcoder::convolution(den, g); for (size_t i = 0; i < den.size(); i++) { den[i] = conv_den_g[i * 2]; } N >>= 1; } return num[0] / den[0]; } int main() { // [x^M] ((1 + 2x)^(N + 1) - (x - x^2)^(N + 1)) / ((1 - x)^(N + 1) (1 + x + x^2)) int N, M; cin >> N >> M; vector num(N * 2 + 3), den(N + 4); for (int d = 0; d <= N + 1; ++d) { mint ncr = fac.ncr(N + 1, d); mint sgn = d % 2 ? -1 : 1; num[d] += mint(2).pow(d) * ncr; num[d * 2 + (N + 1 - d)] -= sgn * ncr; den[d] += ncr * sgn; den[d + 1] += ncr * sgn; den[d + 2] += ncr * sgn; } cout << coefficient_of_rational_function(M, num, den).val() << '\n'; }