#include "bits/stdc++.h"
using namespace std;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second
#define cbr cerr<<"hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ll(x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x,y) (lower_bound(all(x),y)-x.begin())
#define ubd(x,y) (upper_bound(all(x),y)-x.begin())
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline long long rand(long long x, long long y) { return rng() % (y+1-x) + x; } //inclusive
string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?llabs(b):gcd(b%a,a); }

using ll=long long; 
using ld=long double;
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
using pi=pair<ll,ll>; using spi=pair<ll,pi>; using dpi=pair<pi,pi>; 

long long LLINF = 1e18;
int INF = 1e9+1e6;
#define MAXN (5006)
int n, m, mod=998244353, ans, gap[MAXN], memo[MAXN];
ll qexp(ll x,ll e) {
	ll sum=1;
	for(;e;e>>=1,x*=x,x%=mod) if(e&1) sum*=x, sum%=mod;
	return sum;
}
int main() {
	FAST
	cin>>n>>m;
	ans = qexp(m, n) * n % mod;
	// cerr<<ans<<'\n';
	FOR(i,0,m) memo[i]=1;
	FOR(i,0,n) {
		FOR(j,0,m-1) {
			gap[i] += memo[j];
			if(gap[i] >= mod) gap[i] -= mod;
			memo[j] = ll(memo[j]) * j % mod;
		}
	}
	memo[0] = 1; FOR(i,1,n) memo[i] = ll(memo[i-1]) * m % mod;
	FOR(i,1,n) {
		DEC(j,i-1,1) {
			// cerr<<gap[i-j]<<'\n';
			// cerr<<i<<' '<<j<<": "<<qexp(m, j-1 + n-i) * gap[i-j-1] % mod<<'\n';
			ans -= ll(memo[j-1 + n-i]) * gap[i-j-1] % mod;
			if(ans < 0) ans += mod;
		}
	}
	cout<<ans<<'\n';
}


/**
*   author:  akifpathan
*   created: Wednesday 23.06.2021 01:28:14 PM
**/

#ifdef akifpathan
#include "debug.h"
#else
#include<bits/stdc++.h>
using namespace std;
#define debug(x...)
#endif
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
//mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());	

const int mx=1e6+5;

ll f(int n)
{
	return 1LL*n*n;
}

ll dp[mx];
int fre[mx];

int range(int l,int r,int i)
{
	return r/i-(l-1)/i;
}

void solve()
{
	int l,r;
	cin>>l>>r;
	
	for(int i=l;i<=r;i++) 
	{
		int x=i;
		for(int j=1;j*j<=x;j++)
		{
			if(x%j==0)
			{
				fre[j]++;
				fre[x/j]++;
				if(j*j==x) fre[j]--;
			}
		}
	}
	
	for(int i=r;i>=1;i--)
	{
		dp[i]=f(fre[i]);
		for(int j=2*i;j<=r;j+=i) dp[i]-=dp[j];
	}
	
	for(int i=l;i<=r;i++) 
	{
		int temp=range(l,r,i);
		
		dp[i]--;
		temp--;
		
		dp[i]-=(2*temp);
	}
	
	cout<<accumulate(dp+2,dp+r+1,0LL);
}	

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	int testcase=1;
	//cin>>testcase;
	
	for(int i=1;i<=testcase;i++)
	{
		//cout<<"Case "<<i<<": ";
		solve();
	}
	
	#ifdef akifpathan
	cerr<<"\nTime elapsed: " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms\n";
	#endif
	
	
	return 0;
}

