当前位置:网站首页>Find the combination number acwing 886. find the combination number II
Find the combination number acwing 886. find the combination number II
2022-07-27 11:18:00 【T_ Y_ F666】
Find the combination number AcWing 886. Find the combination number II
Original link
AcWing 886. Find the combination number II
Algorithm tags
Combinatorial mathematics Combination count Inverse element Fast power Fermat's small Theorem
Ideas
because (a / b) % p It's not equal to (a % p) / (b % p), So directly dividing by the corresponding factorial doesn't work , Requires factorial inverse elements 
Code
#include<bits/stdc++.h>
#define int long long
#define rep(i, a, b) for(int i=a;i<b;++i)
#define Rep(i, a, b) for(int i=a;i>=b;--i)
using namespace std;
const int N = 2005, mod = 1e9+7;
int f[N], fn[N];
inline int read(){
int s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
return s*w;
}
void put(int x) {
if(x<0) putchar('-'),x=-x;
if(x>=10) put(x/10);
putchar(x%10^48);
}
int qmi(int a, int b, int p){
int ans=1;
while(b){
if(b&1){
ans=(ans*a)%p;
}
a=a*a%p;
b>>=1;
}
return ans;
}
void init(){
f[0]=fn[0]=1;
rep(i, 1, N){
f[i]=f[i-1]*i%mod;
// Inverse element
fn[i]=fn[i-1]*qmi(i, mod-2, mod)%mod;
}
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n=read();
init();
while(n--){
int a=read(), b=read();
printf("%lld\n", f[a]*fn[b]%mod*fn[a-b]%mod);
}
return 0;
}
Originality is not easy.
Reprint please indicate the source
If it helps you Don't forget to praise and support 
边栏推荐
- 记忆化搜索 AcWing 901. 滑雪
- 最长上升子序列模型 AcWing 1010. 拦截导弹
- PAT(乙级)2022年夏季考试
- [FPGA tutorial case 40] communication case 10 -- Verilog implementation of a simple OFDM system based on FPGA
- Regular form form judgment
- An article reveals the NFT strategy of traditional game manufacturers such as Ubisoft
- Background color style modification on table hover in antd
- 数字三角形模型 AcWing 275. 传纸条
- Introduction to software vulnerability analysis (I)
- Learning notes - wechat payment
猜你喜欢

BeautifulSoup的使用

背包模型 AcWing 1022. 宠物小精灵之收服

最长上升子序列模型 AcWing 1014. 登山

树形DP AcWing 285. 没有上司的舞会

ethereum rpc

parsel的使用

Kangaroo cloud stack based on CBO in spark SQL optimization

Openatom openharmony sub forum, see you today at 14:00! Wonderful release of memorabilia attached

数字三角形模型 AcWing 1018. 最低通行费

Digital triangle model acwing 275. pass note
随机推荐
IO stream_ Character stream, IO stream summary, IO stream case summary
Tensorflow tensor operation function set
tensorflow运行报错解决方法
[QNX hypervisor 2.2 user manual]9.9 logger
数字三角形模型 AcWing 275. 传纸条
Yiwen counts NFT projects valued at more than US $100million
洛谷 P3052 [USACO12MAR]Cows in a Skyscraper G
发动机悬置系统冲击仿真-瞬时模态动态分析与响应谱分析
pyquery 的使用
SQL Server2000数据库错误
Background color style modification on table hover in antd
最长上升子序列模型 AcWing 272. 最长公共上升子序列
7 row K with the weakest combat effectiveness in the matrix
Maximized array sum after 13 K negations
Longest ascending subsequence model acwing 272. longest common ascending subsequence
Yonbuilder enables innovation, and the "golden keyboard Award" of the fourth UFIDA developer competition is open!
博弈论 AcWing 891. Nim游戏
Openatom openharmony sub forum, see you today at 14:00! Wonderful release of memorabilia attached
Ten year structure five year life-07 young and vigorous transformation
Thank you for your likes and attention