#include using namespace std; //* ATCODER #include using namespace atcoder; typedef modint998244353 mint; //*/ /* BOOST MULTIPRECISION #include using namespace boost::multiprecision; //*/ typedef long long ll; #define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++) #define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--) template bool chmin(T &a, const T &b) { if (a <= b) return false; a = b; return true; } template bool chmax(T &a, const T &b) { if (a >= b) return false; a = b; return true; } template T max(vector &a){ assert(!a.empty()); T ret = a[0]; for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]); return ret; } template T min(vector &a){ assert(!a.empty()); T ret = a[0]; for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]); return ret; } template T sum(vector &a){ T ret = 0; for (int i=0; i<(int)a.size(); i++) ret += a[i]; return ret; } int calc(int a, int b, int c){ return a*a*a + b*b*b + c*c*c; } //defmodfact const int COMinitMAX = 998244; mint fact[COMinitMAX+1], factinv[COMinitMAX+1]; void modfact(){ fact[0] = 1; for (int i=1; i<=COMinitMAX; i++){ fact[i] = fact[i-1] * i; } factinv[COMinitMAX] = fact[COMinitMAX].inv(); for (int i=COMinitMAX-1; i>=0; i--){ factinv[i] = factinv[i+1] * (i+1); } } mint cmb(int a, int b){ if (a poly_inv(vector &a, int M = -314159265){ if (M == -314159265) M = (int)a.size(); else if (M <= 0) return {}; int n = a.size(); mint r = a[0].pow((ll)(mint::mod())-2); int m = 1; vector res = {r}; while (m < M){ vector f = a; f.resize(2 * m); vector g = res; g.resize(2 * m); internal::butterfly(f); internal::butterfly(g); for (int i=0; i<2*m; i++){ f[i] = f[i] * g[i]; } internal::butterfly_inv(f); for (int i=0; i poly_log(vector &a, int M = -314159265){ if (M == -314159265) M = (int)a.size(); else if (M <= 0) return {}; int n = a.size(); if (n == 1) return vector(M, 0); vector b(n-1); for (int i=0; i t = convolution(b, poly_inv(a, M)); vector ret(M); for (int i=0; i poly_exp(vector &a, int M = -314159265){ if (M == -314159265) M = (int)a.size(); else if (M <= 0) return {}; int n = a.size(); int m = 1; vector res = {1}; while (m < M){ vector f(2*m); for (int i=0; i v = poly_log(res, 2*m); vector w(2*m); for (int i=0; i<2*m; i++) w[i] = f[i] - v[i]; w[0] += 1; vector g = convolution(res, w); res.insert(res.end(), g.begin()+m, g.begin()+2*m); m <<= 1; } res.resize(M); return res; } vector poly_pow_nonzero(vector &a, ll m, ll l){ int n = a.size(); mint bais = a[0].pow(m); mint invs; if (a[0].val() == 0) invs = 0; else invs = a[0].inv(); vector r(n); for (int i=0; i poly_pow(vector &a, ll m, ll l){ int n = a.size(); int ind = 0; for (int i=0; i= l){ return vector(l, 0); } vector ret(g*ind); vector b(n-ind); for (int i=0; i tmp; if (l-g*ind > 0) tmp = poly_pow_nonzero(b, m, l-g*ind); else tmp = {}; ret.insert(ret.end(), tmp.begin(), tmp.end()); return ret; } vector BerlekampMassey(const vector &s) { const int N = (int)s.size(); vector b, c; b.reserve(N + 1); c.reserve(N + 1); b.push_back(mint(1)); c.push_back(mint(1)); mint y = mint(1); for (int ed = 1; ed <= N; ed++) { int l = int(c.size()), m = int(b.size()); mint x = 0; for (int i = 0; i < l; i++) x += c[i] * s[ed - l + i]; b.emplace_back(mint(0)); m++; if (x == mint(0)) continue; mint freq = x / y; if (l < m) { auto tmp = c; c.insert(begin(c), m - l, mint(0)); for (int i = 0; i < m; i++) c[m - 1 - i] -= freq * b[m - 1 - i]; b = tmp; y = x; } else { for (int i = 0; i < m; i++) c[l - 1 - i] -= freq * b[m - 1 - i]; } } reverse(begin(c), end(c)); return c; } mint bostan_mori(ll n, vector p, vector q){ assert(p.size() < q.size()); while (n > 0){ vector qi((int)q.size()); for (int i=0; i<(int)q.size(); i++){ if (i%2==0) qi[i] = q[i]; else qi[i] = -q[i]; } vector qq = convolution(q, qi); q.resize(((int)qq.size()+1)/2); for (int i=0; i<((int)qq.size()+1)/2; i++){ q[i] = qq[2*i]; } vector pp = convolution(p, qi); if (n%2==0){ p.resize(((int)pp.size()+1)/2); for (int i=0; i<((int)pp.size()+1)/2; i++){ p[i] = pp[2*i]; } }else{ p.resize((int)pp.size()/2); for (int i=0; i<(int)pp.size()/2; i++){ p[i] = pp[2*i+1]; } } n/=2; } return p[0]*q[0].inv(); } int main(){ modfact(); int n, m; cin >> n >> m; int mx = 40000; vector f(mx+1); rep(i,0,mx+1){ f[i] = factinv[3*i+1]; } vector g = poly_pow(f, m, mx+1); rep(i,0,mx+1){ g[i] *= fact[3*i+m]; } vector bm = BerlekampMassey(g); //rep(i,0,(int)bm.size()){ // cout << i << ' ' << bm[i].val() << '\n'; //} g.resize((int)bm.size() - 1); vector h = convolution(g, bm); h.resize((int)bm.size() - 1); if ((n-m+3*m)%3 == 0 && n-m >= 0){ cout << bostan_mori((n-m)/3, h, bm).val() << '\n'; }else{ cout << 0 << '\n'; } }