题意:题目已经说的很清楚了吧
题解:打了个表发现是卡特兰数。。太有趣了
把奇数项看成进栈,偶数项看成出栈,则题目转化为从左到右进栈出栈,且进栈数大于出栈数。=卡特兰数
由于p不是质数,用分解质因数的方法求
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAX = 2000001;
const int MAXP = 150001;
int p[MAXP], notp[MAX], cnt;
int Min[MAX];
int tot[MAXP];
int Pow(int a, int b, int MOD){
int ans = 1;
while(b){
if(b & 1) ans = ((long long)ans * a) % MOD;
b >>= 1;
a = ((long long) a * a) % MOD;
}
return ans;
}
inline void Div(int t, int opt){
while(t != 1){
tot[Min[t]] += opt;
t /= p[Min[t]];
}
}
int main(){
freopen("in.txt", "r", stdin);
int n, q; scanf("%d%d", &n, &q);
for(int i = 2; i <= n * 2; i++){
if(!notp[i]) p[++cnt] = i, Min[i] = cnt;
for(int j = 1; j <= cnt && p[j] * i <= n * 2; j++){
notp[p[j] * i] = 1; Min[p[j] * i] = j;
if(i % p[j] == 0) break;
}
}
for(int i = n + 2; i <= n * 2; i++) Div(i, 1);
for(int i = 2; i <= n; i++) Div(i, -1);
long long ans = 1;
for(int i = 1; i <= cnt; i++){
if(tot[i] > 0){
ans = (ans * Pow(p[i], tot[i], q)) % q;
}
}
printf("%lld", ans);
return 0;
}