当前位置:网站首页>Find the combination number acwing 886 Find the combination number II
Find the combination number acwing 886 Find the combination number II
2022-07-03 08:51: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
边栏推荐
- too many open files解决方案
- 22-06-28 西安 redis(02) 持久化机制、入门使用、事务控制、主从复制机制
- URL backup 1
- Find the intersection of line segments
- Unity notes 1
- First Servlet
- PHP mnemonic code full text 400 words to extract the first letter of each Chinese character
- Life cycle of Servlet
- [concurrent programming] consistency hash
- 【Rust 笔记】10-操作符重载
猜你喜欢
DOM 渲染系统(render mount patch)响应式系统
UE4 source code reading_ Bone model and animation system_ Animation node
UE4 source code reading_ Mobile synchronization
Parameters of convolutional neural network
How to place the parameters of the controller in the view after encountering the input textarea tag in the TP framework
I made mistakes that junior programmers all over the world would make, and I also made mistakes that I shouldn't have made
Unity editor expansion - draw lines
Markdown learning
Drawing maze EasyX library with recursive backtracking method
Campus lost and found platform based on SSM, source code, database script, project import and operation video tutorial, Thesis Writing Tutorial
随机推荐
Escape from heaven and forget what he suffered. In ancient times, it was called the punishment of escape from heaven. Article collection
单调栈-84. 柱状图中最大的矩形
Gradle's method of dynamically modifying APK package name
使用dlv分析golang进程cpu占用高问题
樹形DP AcWing 285. 沒有上司的舞會
注解简化配置与启动时加载
producer consumer problem
How to deal with the core task delay caused by insufficient data warehouse resources
Graphics_ Learnopongl learning notes
DOM 渲染系统(render mount patch)响应式系统
Analysis of Alibaba canal principle
Apache startup failed phpstudy Apache startup failed
[rust notes] 11 practical features
Unity interactive water ripple post-treatment
Redux - learning notes
Unity editor expansion - the framework and context of unity imgui
求组合数 AcWing 886. 求组合数 II
[rust note] 10 operator overloading
20220630学习打卡
[rust notes] 06 package and module