#include using namespace std; constexpr int mod = 998244353; long long modpow(long long a,long long b) { long long ans = 1; while(b) { if(b & 1) { (ans *= a) %= mod; } (a *= a) %= mod; b /= 2; } return ans; } int main() { int N,M; cin >> N >> M; int ans = 0,tmp = 1; for(int i = 29; i >= 0; i--) { if((1 << i) <= M) { ans += modpow(N+1,i)*tmp%mod; if(ans >= mod) ans -= mod; tmp = 1ll*N*tmp%mod; M -= (1 << i); } } ans += tmp; if(ans >= mod) ans -= mod; cout << ans << endl; }