用了快速幂、一层 for 循环,同时用了快读,时间复杂度应该是 O(nlogn) 的,但最后两个测试点 TLE 了。
#include<bits/stdc++.h>
using namespace std;
#define LL long long
const LL MOD = 998244353;
int read()
{
int x = 0, w = 1;
char ch = 0;
while(ch < '0' || ch > '9')
{
if(ch == '-') w = -1;
ch = getchar();
}
while(ch >= '0' && ch <= '9')
{
x = x * 10 + ch - '0';
ch = getchar();
}
return x * w;
}
long long fast_pow(long long a, long long b, long long p)
{
LL res = 1;
while(b)
{
if(b & 1) res = res * a % p;
a = a * a % p;
b >>= 1;
}
return res;
}
int main()
{
int n;
n = read();
LL ans = 1;
for(int k = 1; k <= n; k ++)
{
ans = ans * fast_pow((LL)k, 1ll * k * (n - k + 2) * (n - k + 1) / 2, MOD) % MOD;
}
printf("%lld\n", ans);
return 0;
}