#include #include #include using namespace atcoder; using mint = modint998244353; using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf 1000000001 template struct matrix{ F0 func0; F1 func1; vector> value; int height,width; T init_value0,init_value1; matrix(vector> X,F0 f0,F1 f1,T iv0,T iv1):func0(f0),func1(f1){ height = X.size(); width = X[0].size(); value = X; init_value0 = iv0,init_value1 = iv1; } matrix(int h,int w,F0 f0,F1 f1,T iv0,T iv1):func0(f0),func1(f1){ vector> d(h,vector(w,iv0)); height = h,width = w; value = d; init_value0 = iv0,init_value1 = iv1; } void set_1(){ for(int i=0;i R(height,another.width,func0,func1,init_value0,init_value1); for(int i=0;i R(height,width,func0,func1,init_value0,init_value1); R.set_1(); auto temp = *this; while(cnt!=0LL){ if(cnt%2==1){ R *= temp; } temp *= temp; cnt/=2; } return R; } }; int N,K; pair get(){ vector> A(K*K+K*K,vector(K*K+K*K,0)); rep(i,K){ rep(j,K){ rep(k,K){ if(i=j)continue; A[j*K+k][i*K+j] ++; A[K*K + j*K+k][K*K + i*K+j] ++; A[K*K + j*K+k][i*K+j] += k; } if(i>j){ if(k==i)continue; if(k<=j)continue; A[j*K+k][i*K+j] ++; A[K*K + j*K+k][K*K + i*K+j] ++; A[K*K + j*K+k][i*K+j] += k; } } } } auto f0 = [](mint a,mint b){ return a+b; }; auto f1 = [](mint a,mint b){ return a*b; }; matrix AA(A,f0,f1,0,1); AA = AA.beki(N-2); vector> B(K*K+K*K,vector(1)); rep(i,K){ rep(j,K){ if(i==j)continue; B[i*K+j][0] = 1; B[K*K + i*K+j][0] = i+j; } } matrix BB(B,f0,f1,0,1); AA = AA*BB; pair ret(0,0); rep(i,K*K){ ret.first += AA.value[i][0]; ret.second += AA.value[K*K + i][0]; } return ret; } int main(){ cin>>N>>K; pair ret = get(); cout<