题解 P11029 『DABOI Round 1』A Simple Problem
cjh20090318 · · 题解
验题人题解。
出题人标程一开始写错了,所以我重写了 std 并造了数据。
题意
分析
观察到
现在的问题是求
因此我们所求答案:
做到这里其实可以直接求了,但是进一步由费马小定理
然后就可以愉快的枚举
最大点在 C++14 O2 下跑了
//the code is from chenjh
#include<cstdio>
using namespace std;
typedef long long LL;
const int mod=998244353;
int qpow(int a,int b){
int ret=1;
for(;b;b>>=1,a=(LL)a*a%mod)if(b&1)ret=(LL)ret*a%mod;
return ret%mod;
}
int n;
int main(){
scanf("%d",&n);
int ans=1;
for(int i=1;i<=n;i++) ans=(LL)ans*qpow(i,(LL)i*((LL)(n-i+1)*(n-i+2)/2%(mod-1))%(mod-1))%mod;
printf("%d\n",ans);
return 0;
}
Update on 2024/9/9:
用 PyPy 3 写了个解法,可以通过,请不要再说卡常了。
n=int(input())
s=1
for i in range(1,n+1):
s=s*pow(i,i*(n-i+1)*(n-i+2)//2%998244352,998244353)%998244353
print(s)