卡特兰数
#include<bits/stdc++.h>
using namespace std;
long long mp[2000005],p[200005],cnt[2000005],r;
long long qpow(long long a,long long b) {
long long ans=1;
do {
if(b&1)ans=ans*a%r;
a=a*a%r;
} while(b/=2);
return ans;
}
long long main() {
long long n;
cin>>n>>r;
long long pn=0;
for(long long i=2; i<=2*n; i++) {
if(!mp[i]) {
p[++pn]=i;
mp[i]=i;
}
for(long long j=1; j<=pn&&i*p[j]<=2*n; j++) {
mp[i*p[j]]=p[j];
if(i%p[j]==0) break;
}
}
for(long long i=1; i<=n; i++)cnt[i]=-1;
for(long long i=n+2; i<=2*n; i++)cnt[i]=1;
for(long long i=2*n; i>1; i--)
if(mp[i]<i) {
cnt[mp[i]]+=cnt[i];
cnt[i/mp[i]]+=cnt[i];
}
long long ans=1;
for(long long i=2; i<=2*n; i++)if(mp[i]==i)ans=ans*qpow(i,cnt[i])%r;
cout<<ans<<endl;
return 0;
}
标签:2000005,a%,long,mp,P3200,ans
From: https://www.cnblogs.com/zan-mei-tai-yang/p/18445004