提交时间:2026-04-22 19:30:26

运行 ID: 41416

#include<bits/stdc++.h> #define up(i,l,r) for(int i=(l);i<=(r);++i) #define down(i,l,r) for(int i=(l);i>=(r);--i) #define pi pair<int,int> #define p1 first #define p2 second #define m_p make_pair #define pb push_back #define eb emplace_back using namespace std; typedef long long ll; inline ll read(){ ll x=0;short t=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')t=-1;ch=getchar();} while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar(); return x*t; } const int P=998244353; int n,m,C[1005][1005],f[1005][1005]; inline int add(int a,int b){if((a+=b)>=P)a-=P;return a;} void init(){ C[0][0]=1;int n=1000; up(i,1,n){ C[i][0]=1; up(j,1,i)C[i][j]=add(C[i-1][j-1],C[i-1][j]); } } int F(int k){ up(i,0,n/(k+1))f[0][i]=1; up(i,1,n){ up(j,0,n/(k+1)){ f[i][j]=f[i-1][j]*1llu*(m-j)%P; if(i>=k+1)f[i][j]=(f[i][j]+(P-f[i-(k+1)][j+1])*1llu*C[i-1][k]%P*1llu*(m-j))%P; } }return f[n][0]; } void slv(){ m=read(),n=read(); int res=n;up(i,1,n)res=res*1llu*m%P; up(k,1,n-1)res=add(res,P-F(k)); printf("%d\n",res); } int main(){ // freopen("1.in","r",stdin),freopen("1.out","w",stdout); slv(); return 0; }