This documentation is automatically generated by online-judge-tools/verification-helper
#define PROBLEM "http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2987"
#include "../memo/macro.hpp"
#include "../math/modint.cpp"
using mint = modint<998244353>;
#include "../math/combination.cpp"
#include "../math/sum_of_powers.cpp"
signed main(void) {
ll n, s0;
cin >> n >> s0;
mint s = s0;
mint ans = s * (s+1).pow(n-1) / 2;
if(s0%2 == 0) {
ans += mint(2).pow(n) * sum_of_powers(s0/2+1, n-1);
ans -= sum_of_powers(s0+1, n-1);
} else {
ans -= mint(2).pow(n) * sum_of_powers(s0/2+1, n-1);
ans += sum_of_powers(s0+1, n-1);
}
cout << ans << endl;
return 0;
}
#line 1 "test/aoj2987.test.cpp"
#define PROBLEM "http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2987"
#line 1 "memo/macro.hpp"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
const ll INF = 1LL<<60;
#line 1 "math/modint.cpp"
// BEGIN CUT
template<ll MOD>
struct modint {
ll x;
modint(): x(0) {}
modint(ll y) : x(y>=0 ? y%MOD : y%MOD+MOD) {}
static constexpr ll mod() { return MOD; }
// e乗
modint pow(ll e) {
ll a = 1, p = x;
while(e > 0) {
if(e%2 == 0) {p = (p*p) % MOD; e /= 2;}
else {a = (a*p) % MOD; e--;}
}
return modint(a);
}
modint inv() const {
ll a=x, b=MOD, u=1, y=1, v=0, z=0;
while(a) {
ll q = b/a;
swap(z -= q*u, u);
swap(y -= q*v, v);
swap(b -= q*a, a);
}
return z;
}
// Comparators
bool operator <(modint b) { return x < b.x; }
bool operator >(modint b) { return x > b.x; }
bool operator<=(modint b) { return x <= b.x; }
bool operator>=(modint b) { return x >= b.x; }
bool operator!=(modint b) { return x != b.x; }
bool operator==(modint b) { return x == b.x; }
// Basic Operations
modint operator+(modint r) const { return modint(*this) += r; }
modint operator-(modint r) const { return modint(*this) -= r; }
modint operator*(modint r) const { return modint(*this) *= r; }
modint operator/(modint r) const { return modint(*this) /= r; }
modint &operator+=(modint r) {
if((x += r.x) >= MOD) x -= MOD;
return *this;
}
modint &operator-=(modint r) {
if((x -= r.x) < 0) x += MOD;
return *this;
}
modint &operator*=(modint r) {
#if !defined(_WIN32) || defined(_WIN64)
x = (ll)x * r.x % MOD; return *this;
#endif
unsigned long long y = (unsigned long long)x * r.x;
unsigned xh = (unsigned) (y >> 32), xl = (unsigned) y, d, m;
asm(
"divl %4; \n\t"
: "=a" (d), "=d" (m)
: "d" (xh), "a" (xl), "r" (MOD)
);
x = m;
return *this;
}
modint &operator/=(modint r) { return *this *= r.inv(); }
// increment, decrement
modint operator++() { x++; return *this; }
modint operator++(signed) { modint t = *this; x++; return t; }
modint operator--() { x--; return *this; }
modint operator--(signed) { modint t = *this; x--; return t; }
// 平方剰余のうち一つを返す なければ-1
friend modint sqrt(modint a) {
if(a == 0) return 0;
ll q = MOD-1, s = 0;
while((q&1)==0) q>>=1, s++;
modint z=2;
while(1) {
if(z.pow((MOD-1)/2) == MOD-1) break;
z++;
}
modint c = z.pow(q), r = a.pow((q+1)/2), t = a.pow(q);
ll m = s;
while(t.x>1) {
modint tp=t;
ll k=-1;
FOR(i, 1, m) {
tp *= tp;
if(tp == 1) { k=i; break; }
}
if(k==-1) return -1;
modint cp=c;
REP(i, m-k-1) cp *= cp;
c = cp*cp, t = c*t, r = cp*r, m = k;
}
return r.x;
}
template<class T>
friend modint operator*(T l, modint r) { return modint(l) *= r; }
template<class T>
friend modint operator+(T l, modint r) { return modint(l) += r; }
template<class T>
friend modint operator-(T l, modint r) { return modint(l) -= r; }
template<class T>
friend modint operator/(T l, modint r) { return modint(l) /= r; }
template<class T>
friend bool operator==(T l, modint r) { return modint(l) == r; }
template<class T>
friend bool operator!=(T l, modint r) { return modint(l) != r; }
// Input/Output
friend ostream &operator<<(ostream& os, modint a) { return os << a.x; }
friend istream &operator>>(istream& is, modint &a) {
is >> a.x;
a.x = ((a.x%MOD)+MOD)%MOD;
return is;
}
friend string to_frac(modint v) {
static map<ll, PII> mp;
if(mp.empty()) {
mp[0] = mp[MOD] = {0, 1};
FOR(i, 2, 1001) FOR(j, 1, i) if(__gcd(i, j) == 1) {
mp[(modint(i) / j).x] = {i, j};
}
}
auto itr = mp.lower_bound(v.x);
if(itr != mp.begin() && v.x - prev(itr)->first < itr->first - v.x) --itr;
string ret = to_string(itr->second.first + itr->second.second * ((int)v.x - itr->first));
if(itr->second.second > 1) {
ret += '/';
ret += to_string(itr->second.second);
}
return ret;
}
};
// END CUT
#line 4 "test/aoj2987.test.cpp"
using mint = modint<998244353>;
#line 1 "math/combination.cpp"
// BEGIN CUT
// 前計算O(N) クエリO(1)
mint combi(ll N, ll K) {
const int maxN=5e5; // !!!
static mint fact[maxN+1]={},factr[maxN+1]={};
if (fact[0]==0) {
fact[0] = factr[0] = 1;
FOR(i, 1, maxN+1) fact[i] = fact[i-1] * i;
factr[maxN] = fact[maxN].inv();
for(ll i=maxN-1; i>=0; --i) factr[i] = factr[i+1] * (i+1);
}
if(K<0 || K>N) return 0; // !!!
return factr[K]*fact[N]*factr[N-K];
}
// 前計算O(Klog(mod)) クエリO(K)
mint combi_bigN(ll N, ll K) {
const int maxN=5e5; // !!!
static mint inv[maxN+1] = {};
if(inv[0]==0) {
inv[0] = 1;
FOR(i, 1, maxN+1) inv[i] = mint(i).inv();
}
if(K<0 || K>N) return 0; // !!!
mint ret = 1;
for(;K>0;N--,K--) ret *= N, ret *= inv[K];
return ret;
}
// END CUT
#line 1 "math/sum_of_powers.cpp"
// BEGIN CUT
// \sum_{i=0}^{n-1} i^k O(k^2)
// kが固定でクエリがいっぱいならベルヌーイ数を前計算で高速化
mint sum_of_powers(ll n, ll k) {
vector<mint> b(k+1), po(k+2);
b[0] = po[0] = 1;
FOR(i, 1, k+2) po[i] = po[i-1] * n;
FOR(i, 1, k+1) {
REP(j, i) b[i] += combi(i+1, j) * b[j];
b[i] /= -(i+1);
}
mint sum = 0;
REP(i, k+1) sum += combi(k+1, i) * b[i] * po[k+1-i];
return sum / (k+1);
}
// END CUT
// FPSとかでベルヌーイ数をklogkとかあるっぽい…?
#line 7 "test/aoj2987.test.cpp"
signed main(void) {
ll n, s0;
cin >> n >> s0;
mint s = s0;
mint ans = s * (s+1).pow(n-1) / 2;
if(s0%2 == 0) {
ans += mint(2).pow(n) * sum_of_powers(s0/2+1, n-1);
ans -= sum_of_powers(s0+1, n-1);
} else {
ans -= mint(2).pow(n) * sum_of_powers(s0/2+1, n-1);
ans += sum_of_powers(s0+1, n-1);
}
cout << ans << endl;
return 0;
}