当前位置:网站首页>Mathematical knowledge: finding combinatorial number II - finding combinatorial number
Mathematical knowledge: finding combinatorial number II - finding combinatorial number
2022-06-29 16:29:00 【Fight! Sao Nian!】
subject :AcWing 886. Find the combination number II
Given n Group inquiry , Each group is given two integers a,b, Please output Cbamod(109+7) Value .
Input format
The first line contains integers n.
Next n That's ok , Each line contains a set of a and b.
Output format
common n That's ok , Each line outputs a solution to the query .
Data range
1≤n≤10000,
1≤b≤a≤105
sample input :
3
3 1
5 3
2 2
sample output :
3
10
1
Topic analysis :
This problem is a preprocessed factorial
Because combinations can be replaced by factorial forms 
But the division should be replaced by the inverse , So we need to use the knowledge of fast power to find the inverse element .
Last fact[i] Express i The factorial ,infact[i] Express i Inverse element
Cab=fact[a] * infact[a-b] * infact[b]
#include <iostream>
using namespace std;
typedef long long LL;
const int N = 100010,mod=1e9+7;
int fact[N],infact[N];
int qmi(int a, int k, int p)
{
int res = 1;
while(k)
{
if(k&1)res=(LL)res*a%p;
a=(LL)a*a%p;
k>>=1;
}
return res;
}
int main()
{
fact[0]=infact[0]=1;
for(int i=1;i<N;i++) // Preprocessing
{
fact[i]=(LL)fact[i-1]*i%mod; // Factorial
infact[i]=(LL)infact[i-1]*qmi(i,mod-2,mod)%mod; // Inverse of factorial
}
int n;
cin>>n;
while(n--)
{
int a,b;
cin>>a>>b;
cout<<(LL)fact[a]*infact[b]%mod*infact[a-b]%mod<<endl;
}
return 0;
}
边栏推荐
- Accelerate the implementation of intelligent driving projects? You still lack a truth evaluation system
- 或许再过两年,ASML将可以自由给中国供应EUV光刻机
- UWB precise positioning scheme, centimeter level high-precision technology application, intelligent pairing induction technology
- 关于组织开展2022年南京市创新产品(第一批)申报工作的通知
- locust性能压测工具
- 又拍云 Redis 的改进之路
- Summary of common MySQL statements and commands
- leetcode:232. Realize queue with stack [two stacks, one auxiliary and one simulated queue]
- 【第28天】给定一个字符串S,请你判断它是否为回文字符串 | 回文的判断
- scratch报时的公鸡 电子学会图形化编程scratch等级考试一级真题和答案解析2022年6月
猜你喜欢

Summary of common MySQL statements and commands

The third sprint of Wei long La Tiao: the growth rate of performance declined, and Liu Weiping and Liu Fuping cashed out in advance

UWB精准定位方案,厘米级高精度技术应用,智能配对感应技术

The rooster Electronic Society graphical programming real questions and answers analysis of the scratch grade test level 1 June 2022

教程|fNIRS数据处理工具包Homer2下载与安装

C# Winfrom Chart图表控件 柱状图、折线图

A tour of grpc:02 - generate code from proto

Self taught programming can understand the code, but what if you can't write it yourself

贪婪的苹果计划提高iPhone14的价格,这将为中国手机提供机会

Tool chain empowers hundreds of companies, horizon opens the "Matthew effect" of mass production of intelligent driving
随机推荐
技术分享| 融合调度中的广播功能设计
scratch报时的公鸡 电子学会图形化编程scratch等级考试一级真题和答案解析2022年6月
事件相关电位ERP的皮层溯源分析
按键精灵打怪学习-窗口绑定技能
星环科技数据安全管理平台 Defensor重磅发布
「BUAA OO Unit 4 HW16」第四单元总结与课程回顾
Small programs have a "big" role in the industrial Internet
Cv5200 ad hoc network remote WiFi module, UAV wireless image transmission application, HD low delay scheme
数学知识复习:第一型曲线积分
自学编程能看得懂代码,但是自己写不出来怎么办
leetcode:535. Encryption and decryption of tinyurl [mapping of URL and ID, ID self increment]
MySQL foundation - transaction
京东方:随着下半年旺季到来、促销拉动、新产品发布等影响,需求有望出现好转
C11新特性——auto、decltype类型指示符
What are the financial products suitable for the poor in 2022?
全面剖析Seata 分布式事务 AT 与XA
Which version of JVM is the fastest?
How to install WordPress on a web site
Differences between virtual hosts, WordPress hosts and virtual hosts
元数据管理Apache Atlas编译集成部署及测试