当前位置:网站首页>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 
边栏推荐
- 基于SSM的校园失物招领平台,源码,数据库脚本,项目导入运行视频教程,论文撰写教程
- [concurrent programming] atomic operation CAS
- Unity interactive water ripple post-treatment
- UE4 source code reading_ Bone model and animation system_ Animation node
- DOM 渲染系统(render mount patch)响应式系统
- Common DOS commands
- [rust notes] 02 ownership
- Campus lost and found platform based on SSM, source code, database script, project import and operation video tutorial, Thesis Writing Tutorial
- How to delete CSDN after sending a wrong blog? How to operate quickly
- Binary tree sorting (C language, char type)
猜你喜欢

SQL statement error of common bug caused by Excel cell content that is not paid attention to for a long time

Monotonic stack -84 The largest rectangle in the histogram

Life cycle of Servlet
![[concurrent programming] working mechanism and type of thread pool](/img/51/d21428a7c95c0a5177e8198742e78c.jpg)
[concurrent programming] working mechanism and type of thread pool

Concurrent programming (III) detailed explanation of synchronized keyword

Alibaba canal actual combat

Thymeleaf 404 reports an error: there was unexpected error (type=not found, status=404)

too many open files解决方案

Graphics_ Learnopongl learning notes

Query XML documents with XPath
随机推荐
Query XML documents with XPath
Redux - learning notes
JS ternary operator - learning notes (with cases)
使用dlv分析golang进程cpu占用高问题
Monotonic stack -42 Connect rainwater
[rust notes] 06 package and module
Unity editor expansion - window, sub window, menu, right-click menu (context menu)
Markdown learning
求组合数 AcWing 886. 求组合数 II
Find the intersection of line segments
[concurrent programming] thread foundation and sharing between threads
file_ put_ contents
Message queue for interprocess communication
Markdown directory generation
[concurrent programming] collaboration between threads
Gif remove blank frame frame number adjustment
Solution of 300ms delay of mobile phone
Sending and receiving of request parameters
[MySQL] MySQL Performance Optimization Practice: introduction of database lock and index search principle
TP5 order multi condition sort