#include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; const ll INF=1LL<<60; typedef pair P; typedef pair PP; const ll MOD=998244353; const double PI=acos(-1); ll mod_pow(ll x,ll y,ll mod){ ll res=1; while(y>0){ if(y&1){ res*=x; res%=mod; } x*=x; x%=mod; y/=2; } return res; } int main(){ int N,M; cin>>N>>M; /* ll ans=0; for(int x=0;x<=M;x++){//Mが大きいのでこれでは無理 int c=__builtin_popcount(x); ans+=mod_pow(N,c,MOD); ans%=MOD; } cout< dp; auto dfs=[&](auto f,int m,int i)->void{ if(dp.count(P{m,i})) return; if(m==0){ dp[P{m,i}]=i; return; } f(f,m/2,0); f(f,m/2,1); if(i==1){ if(m%2==1){ dp[P{m,1}]+=dp[P{m/2,1}]*N%MOD; dp[P{m,1}]%=MOD; dp[P{m,1}]+=dp[P{m/2,1}]; dp[P{m,1}]%=MOD; }else{ //mが偶数 dp[P{m,1}]+=dp[P{m/2,0}]*N%MOD; dp[P{m,1}]%=MOD; dp[P{m,1}]+=dp[P{m/2,1}]; dp[P{m,1}]%=MOD; } }else{ f(f,m/2,1); f(f,m/2,0); if(m%2==1){ dp[P{m,0}]+=dp[P{m/2,0}]*N%MOD; dp[P{m,0}]%=MOD; dp[P{m,0}]+=dp[P{m/2,1}]; dp[P{m,0}]%=MOD; }else{ //mが偶数 dp[P{m,0}]+=dp[P{m/2,0}]*N%MOD; dp[P{m,0}]%=MOD; dp[P{m,0}]+=dp[P{m/2,0}]; dp[P{m,0}]%=MOD; } } return; }; dfs(dfs,M,1); ll ans=dp[P{M,1}]; cout<