https://www.luogu.org/problemnew/show/3807

题目背景

这是一道模板题。

题目描述

给定n,m,p(1\le n,m,p\le 10^51≤n,m,p≤105)

求 C_{n+m}^{m}\ mod\ pCn+mm​ mod p

保证P为prime

C表示组合数。

一个测试点内包含多组数据。

输入输出格式

输入格式:

第一行一个整数T(T\le 10T≤10),表示数据组数

第二行开始共T行,每行三个数n m p,意义如上

输出格式:

共T行,每行一个整数表示答案。

输入输出样例

输入样例#1: 复制

2
1 2 5
2 1 5
输出样例#1: 复制

3
3
 #include <cstdio>

 #define LL long long
inline void read(int &x)
{
x=; register char ch=getchar();
for(; ch>''||ch<''; ) ch=getchar();
for(; ch>=''&&ch<=''; ch=getchar()) x=x*+ch-'';
}
const int N(1e5+);
LL fac[N]; inline LL Pow(LL a,int b,int p)
{
LL ret=;
for(; b; b>>=,a*=1ll*a,a%=p)
if(b&) ret*=1ll*a,ret%=p;
return ret;
} inline LL C(LL n,LL m,LL p)
{
if(n<m) return ;
return fac[n]%p*Pow(fac[m],p-,p)%p*Pow(fac[n-m],p-,p)%p;
} inline LL lus(LL n,LL m,LL p)
{
if(m==) return ;
return C(n%p,m%p,p)*lus(n/p,m/p,p)%p;
} int Presist()
{
int t; read(t); fac[]=;
for(int n,m,p; t--; )
{
read(n),read(m),read(p);
for(int i=; i<=n+m; ++i)
fac[i]=1ll*fac[i-]%p*i%p;
printf("%lld\n",lus(n+m,m,p));
}
return ;
} int Aptal=Presist();
int main(int argc,char**argv){;}

最新文章

  1. cocoa框架 for iOS
  2. 【CityHunter】通过Unity3D来制作游戏中AR部分的内容
  3. [Redis]通过代码配置Redis
  4. 关于sql用&lt;&gt;不等于查询数据不对问题
  5. ECMAScript 6教程 (一)
  6. 结对编程—黄金点游戏WinForm单机版
  7. HTTP Proxy Servlet 代理服务使用
  8. 当碰到unix纪元问题时strtotime怎么转时间戳(DateTime类的使用方法)
  9. cordova Process finished with exit code -1
  10. Error: opening registry key &#39;Software\JavaSoft\Java Runtime Environment&#39; Error: could not find java.dll
  11. node-webkit 使用nodejs第三方C/C++插件
  12. Android定位功能(二)
  13. Linux常用命令及重要目录文件分析总结
  14. Strace跟踪解决expect乱码问题
  15. PHP自动测试框架Top 10
  16. UE4使用C++创建枚举变量适用于C++与蓝图
  17. c语言编译四大步
  18. daemon_inetd函数
  19. LeetCode 232:Implement Queue using Stacks
  20. verilog task1

热门文章

  1. 《Java并发编程实战》读书笔记一 -- 简介
  2. Primer C++第五版 读书笔记(一)
  3. (转)iOS平台UDID方案比较
  4. spring事务(Transaction )报 marked as rollback-only异常的原因及解决方法
  5. linux 安装elasticsearch
  6. 关于stm32优先级大小的理解
  7. nslookup、dig命令Linux安装包
  8. viewController备注
  9. 牛客练习赛22 C 简单瞎搞题
  10. Java基础之封装