官方题解
int n, m, Q, K, mod = 998244353;
// int psum[MAXN], pmul[MAXN], ansA[MAXN], ansB[MAXN];
int dp[MAXN];
int fp(int a, int b) {
int ret = 1;
while(b) {
if(b & 1) ret = (ret * a) % mod;
a = a*a % mod;
b >>= 1;
}
return ret;
}
signed main() {
#ifdef debug
freopen("test.txt", "r", stdin);
clock_t stime = clock();
#endif
read(Q);
/**
ansA[1] = ansB[1] = psum[1] = pmul[1] = 1;
for(int i=2; i<MAXN; i++) {
psum[i] = ( psum[i-1] + i*1L ) % mod;
pmul[i] = ( pmul[i-1] * i*1L) % mod;
}
for(int i=2; i<MAXN; i++) {
ansA[i] = (psum[i] + ansA[i-1]*1L) % mod;
ansB[i] = (pmul[i] + ansB[i-1]*1L) % mod;
}
while(Q--) {
read(n);
printf("%d %d\n", ansA[n], ansB[n]);
}
*/
dp[0] = 1;
for(int i=1; i<MAXN; i++) dp[i] = (dp[i-1] * i)%mod;
while(Q--) {
read(n);
int lef = (n*(n+1)>>1) % mod;
lef = ((lef % mod) * (lef % mod) ) % mod;
int rig = fp(fp(dp[n], n), 2);
printf("%lld %lld\n", lef, rig);
}
#ifdef debug
clock_t etime = clock();
printf("rum time: %lf 秒\n",(double) (etime-stime)/CLOCKS_PER_SEC);
#endif
return 0;
}