传送门

Solution

卡特兰数 排队问题的简单变化 答案为\(C_{2n}^n \pmod p\)

由于没有逆元,只好用分解质因数,易证可以整除

Code

//By Menteur_Hxy
#include <ctime>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define Re register
#define Ms(a,b) memset(a,(b),sizeof(a))
#define Fo(i,a,b) for(Re int i=(a),_=(b);i<=_;i++)
#define Ro(i,a,b) for(Re int i=(b),_=(a);i>=_;i--)
using namespace std;
typedef long long LL; inline int read() {
int x=0,f=1;char c=getchar();
while(!isdigit(c)) {if(c=='-')f=-f;c=getchar();}
while(isdigit(c)) x=(x<<1)+(x<<3)+c-48,c=getchar();
return x*f;
} const int N=2e6+10;
int tot,ans=1,n,MOD;
bool vis[N];
int pri[N],d[N]; void init(int Lim) {
Fo(i,2,Lim) {
if(!vis[i]) pri[++tot]=i;
for(Re int j=1;i*pri[j]<=Lim&&j<=tot;j++) {
vis[i*pri[j]]=1;
if(i%pri[j]==0) break;
}
}
} void Divid(int x,int w) {
for(Re int i=1;i<=tot&&pri[i]*pri[i]<=x;i++)
while(x%pri[i]==0) x/=pri[i],d[pri[i]]+=w;
if(x>1) d[x]+=w;//!!!
} LL qpow(LL a,int b) {LL t=1;for(;b;b>>=1,a=a*a%MOD)if(b&1)t=t*a%MOD;return t;} int main() {
n=read(),MOD=read();init(n+n);Divid(n+1,-1);
Fo(i,n+1,n+n) Divid(i,1); Fo(i,1,n) Divid(i,-1);
Fo(i,1,n+n) ans=1ll*ans*qpow(i,d[i])%MOD;
printf("%d",ans);
return 0;
}

最新文章

  1. Denormalization
  2. 前端开发编辑器(notepad++、sublime text)
  3. C语言 04 进制
  4. apache https 伪静态
  5. java : 包装类 缓冲机制的使用(转载)
  6. Tensorflow学习笔记4:分布式Tensorflow
  7. Support Vector Machine (1) : 简单SVM原理
  8. Week1 Java 基础知识
  9. ofbiz的部署及安装问题解决办法
  10. poj 1129 Channel Allocation ( dfs )
  11. linux多线程编程(转)
  12. Python:staticmethod vs classmethod
  13. CppCMS URL使用
  14. 简单的三层asp.net webForm使用Ninject实现Ioc
  15. MATLAB &#39; : &#39; 官方解释
  16. ionic3 app 退出应用程序
  17. 回文自动机(PAM) 学习笔记
  18. 关于controller的书写
  19. POJ3417 LCA+树dp
  20. 10.13 Django随笔

热门文章

  1. 大写金额换算器iOS版源码
  2. Prevent the &quot;split brain&quot; by configuring the majority of nodes
  3. JS高级技巧学习小结
  4. codility MinAbsSum
  5. bzoj 1822 冷冻波
  6. bzoj3240 [Noi2013]矩阵游戏——费马小定理+推式子
  7. RDA 字库制作
  8. PCB 录屏工具Screen2Exe GifCam ScreenToGif
  9. 湖南集训day3
  10. Java转大数据开发全套视频资料