当前位置:网站首页>没那么大的组合数
没那么大的组合数
2022-07-17 06:45:00 【2020100XWH】
直接计算
再大且p 1e5这样的话配合卢卡斯处理
线性求逆元
p-2逆元
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+50;
int p,inv[N],a[N];
void invv()
{
inv[1]=1;
for(int i=2;i<=N;++i)
{
inv[i]=(p-(p/i))*inv[p%i]%p;
}
return ;
}
ll qpow(ll a,ll b)
{
ll ans=1;
while(b)
{
if(b&1)
{
ans=(ans*a)%p;
}
a=(a*a)%p;
b>>=1;
}
return ans;
}
ll mm(ll x)
{
return qpow(x,p-2);
}
ll c(ll n,ll m)
{
ll ans=1;
for(ll i=1,j=n-m+1;i<=m;++i,++j)
{
ans=(ans*mm(i))%p;
ans=(ans*j)%p;
}
return ans;
}
int main ()
{
int t;
cin>>t;
while(t--)
{
ll n,m;
cin>>n>>m>>p;
cout<<c(n,m)<<"\n";
}
return 0;
}边栏推荐
- Standard Version (release and changelog Automation)
- Paddleserving服务化部署 tensorrt报错, shape of trt subgraph is [-1,-1,768],
- Junit5
- 【flask入门系列】请求钩子与上下文
- 养老年金保险有必要买吗?适合老人的养老年金产品有哪些?
- standard-version(发版与 Changelog 自动化)
- Beijing Jiewen technology, an acquiring outsourcing service provider, transferred 60% of its shares for about 480million
- [characteristic Engineering]
- 本地存储 sessionStorage
- redis缓存雪崩、穿透、击穿
猜你喜欢
随机推荐
How does the V8 engine recycle garbage memory?
牛客题目——打家劫舍一、打家劫舍二
Understand LSTM and Gru
JS array intersection, subtraction and union
Regular expression extraction of matching content
【JVM】之堆内存、逃逸分析、栈上分配、同步省略、标量替换详解
Use of mongodb
STM32F103C8T6硬件IIC控制4针0.96寸OLED显示屏
【MySQL】 事务:事务基础知识、MySQL事务实现原理、事务日志 redolog & undolog 详解
Error received from peer ipv4/Connection reset by peer Paddleserving服务化部署后报错
面试题:外边距折叠问题 (块级元素在普通文档流中的BUG)
DP动态规划企业级模板分析(数字三角,上升序列,背包,状态机,压缩DP)
类型详解·自定义类型·结构体初识
Mongodb index
Xilinx ultrascale+ MPSoC (zu9eg/zu15eg) high performance PCIe data preprocessing board
C语言一个数如果恰好等于它的因子之和,这个数就称为“完数”。例如6=1+2+3.编程
What if the user information in the website app database is leaked and tampered with
V8 引擎如何进行垃圾内存的回收?
History and value of forked coins | eth, BCH, BSV 2020-03-08
Modify radio style








