QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#663117#9486. Random Mexicpc_zhzx034#ML 0ms0kbC++141.7kb2024-10-21 13:22:482024-10-21 13:22:53

Judging History

你现在查看的是最新测评结果

  • [2024-10-21 13:22:53]
  • 评测
  • 测评结果:ML
  • 用时:0ms
  • 内存:0kb
  • [2024-10-21 13:22:48]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <ll,ll> P;
#define _for(x,y,z) for (int x(y),_(z); x<=_; ++x)
#define _rep(x,y,z) for (int x(y),_(z); x>=_; --x)
inline ll read(){ ll x; cin>>x; return x; }
inline void _init(){
	#ifdef LOCAL
		assert(freopen("test.in", "r", stdin));
		assert(freopen("test.out", "w", stdout));
	#endif
	ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
}
const ll mod = 998244353;

inline ll qpow(ll a,ll b){
	ll ans=1,base=a;
	while(b){
		if(b&1) ans=ans*base%mod;
		base=base*base%mod;
		b>>=1;
	}
	return ans;
}
ll n,m;
ll dp[8005][8005],pw[8005][8005];
ll C[8005][8005],S[8005][8005],fac[8005];
void init() {
	fac[0]=1;
	for(ll i=0;i<=8001;i++){
		pw[i][0]=1;
		if(i) fac[i]=fac[i-1]*i%mod;
		for(ll j=1;j<=8001;j++) pw[i][j]=pw[i][j-1]*i%mod;
	}
	C[0][0]=1;
	for(ll i=1;i<=8001;i++){
		C[i][0]=1;
		for(ll j=1;j<=i;j++) C[i][j]=(C[i-1][j]+C[i-1][j-1])%mod;
	}
	S[0][0]=1;
	for(ll i=1;i<=8001;i++){
		S[i][0]=0;
		for(ll j=1;j<=i;j++){
			S[i][j]=(S[i-1][j-1]+j*S[i-1][j])%mod;
		}
	}
}

void procedure() {
	n=read(), m=read();
	ll ans=0;
	// for(ll j=0;j<=m;j++){
	// 	if(j&1) ans=(ans-pw[j][n]*C[m+1][j]%mod+mod)%mod;
	// 	else ans=(ans+pw[j][n]*C[m+1][j])%mod;
	// }

	// for(ll i=0;i<=n && i<=m;i++){
		// ll coef = S[n][i] * fac[i] % mod * C[m+1][i] % mod;
		// ans = (ans + coef) % mod;
	// }
	ans = qpow(m+1, n);
	if(n > m){
		ans = (ans - S[n][m+1] * fac[m+1] % mod + mod) % mod;
	}
	// if(m&1) ans=(mod-ans)%mod;
	cout<<(ans * qpow(qpow(m, n), mod-2) + mod - 1) % mod <<endl;
}

int main() {
	_init(), init();
	int T=read();
	while(T--) procedure();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Memory Limit Exceeded

input:

4
3 2
1 1
20 23
8000 8000

output:

374341634
1
111675632
994279778

result: