#include using namespace std; #define MOD 1000000007 #define MOD2 998244353 #define rep(i,n) for (long long i = 0; i < (long long)(n); i++) #define reps(i,s,n) for (long long i = (long long)(s); i < (long long)(n); i++) #define pr(a) cout << a #define prl(a) cout << (a) << endl #define prld(a) cout << setprecision(15)<< (a) << endl #define allrange(a) a.begin(),a.end() long long mypow(long long x, long long n) { long long ret = 1; while (n > 0) { if (n & 1) ret = ret * x % MOD2; // n の最下位bitが 1 ならば x^(2^i) をかける x = x * x % MOD2; n >>= 1; // n を1bit 左にずらす } return ret; } long long sum(long long s,long long t){ return (((t-s+1)*(t+s))/2)%MOD2; } long long getsum(long long s,long long t,long long n){ long long a = sum(s,t); long long b = mypow((t-s+1),n-1); return (((a*b)%MOD2)*n)%MOD2; } void solve(long long N, long long M){ long long n= N%MOD2; long long X1 = getsum(1,M,n); X1 = (X1*M)%MOD2; long long X2 = 0; rep(i,M){ long long buf = getsum(i+1,M,n); X2 = (X2+buf)%MOD2; } X2 = MOD2-X2; long long X3 = 0; rep(i,M-1){ long long buf = getsum(1,i+1,n); X3 = (X3+buf)%MOD2; } X3 = MOD2-X3; long long ans = (X1+X2+X3)%MOD2; prl(ans); } int main(){ std::cin.tie(0); // cinとcoutの同期を解除 std::ios::sync_with_stdio(false); //1変数入力 long long N,M; cin >> N >> M; solve(N,M); }