当前位置:网站首页>AcWing 886. Finding combinatorial number II (pretreatment factorial)
AcWing 886. Finding combinatorial number II (pretreatment factorial)
2022-07-01 04:51:00 【MangataTS】
Topic link
https://www.acwing.com/problem/content/description/888/
Ideas
This data range is even larger , So we can't use recursion at this time , Because I can't save it , Second, the complexity is too high , So we can start from the definition of combinatorial number : C a b = a ! ( a − b ) ! × b ! C_a^b=\frac{a!}{(a-b)!\times b!} Cab=(a−b)!×b!a!, So now we just need to 1e5 All factorials within and the inverse preprocessing of factorials are OK , So the problem is solved
Code
#include<bits/stdc++.h>
using namespace std;
//---------------- Custom part ----------------
#define ll long long
#define mod 1000000007
#define endl "\n"
#define PII pair<int,int>
#define INF 0x3f3f3f3f
int dx[4] = {
-1, 0, 1, 0}, dy[4] = {
0, 1, 0, -1};
ll ksm(ll a,ll b) {
ll ans = 1;
for(;b;b>>=1LL) {
if(b & 1) ans = ans * a % mod;
a = a * a % mod;
}
return ans;
}
ll lowbit(ll x){
return -x & x;}
const int N = 2e6+10;
//---------------- Custom part ----------------
ll t,n,m,q,fact[N],invfact[N];
void init(){
invfact[0]= fact[0] = 1;// initialization
for(int i = 1;i < N; ++i) {
fact[i] = fact[i-1] * i % mod;
invfact[i] = ksm(fact[i],mod-2);
}
}
void slove(){
ll a,b;
cin>>a>>b;
cout<<(fact[a] * invfact[a-b]) % mod * invfact[b] % mod <<endl;
}
int main()
{
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
init();
cin>>t;
while(t--){
slove();
}
return 0;
}
边栏推荐
- Manually implement a simple stack
- 解决:拖动xib控件到代码文件中,报错setValue:forUndefinedKey:this class is not key value coding-compliant for the key
- STM32扩展板 温度传感器和温湿度传感器的使用
- Construction of Meizhou nursing laboratory: equipment configuration
- Some tools that research dogs may need
- LeetCode_ 53 (maximum subarray and)
- Print stream and system setout();
- AssertionError assert I.ndim == 4 and I.shape[1] == 3
- 1076 Forwards on Weibo
- 对象的序列化与反序列化
猜你喜欢

CF1638E. Colorful operations Kodori tree + differential tree array

Distributed - summary list

LeetCode522-最长特殊序列II-哈希表-字符串-双指针

Neural networks - use of maximum pooling

分布式架构系统拆分原则、需求、微服务拆分步骤

C read / write application configuration file app exe. Config and display it on the interface

Use and modification of prior network model

Common methods in transforms
![AssertionError assert I.ndim == 4 and I.shape[1] == 3](/img/b1/0109bb0f893eb4c8915df36c100907.png)
AssertionError assert I.ndim == 4 and I.shape[1] == 3

技术分享| 融合调度中的广播功能设计
随机推荐
解决qiankun中子应用外链文件无法获取
【暑期每日一题】洛谷 P1568 赛跑
【硬十宝典】——2.【基础知识】开关电源各种拓扑结构的特点
Pico neo3 handle grabs objects
【暑期每日一题】洛谷 P7222 [RC-04] 信息学竞赛
【暑期每日一题】洛谷 P3742 umi的函数
js解决浮点数相乘精度丢失问题
洗个冷水澡吧
Principle, technology and implementation scheme of data consistency in distributed database
Pytoch (IV) -- visual tool visdom
解决:拖动xib控件到代码文件中,报错setValue:forUndefinedKey:this class is not key value coding-compliant for the key
Oracle views the creation time of the tablespace in the database
Basic exercise of test questions hexadecimal to decimal
Serialization and deserialization of objects
Common UNIX Operation and maintenance commands of shell
C read / write application configuration file app exe. Config and display it on the interface
Thoughts on the construction of Meizhou cell room
Leecode records the number of good segmentation of 1525 strings
LeetCode_58(最后一个单词的长度)
How do I sort a list of strings in dart- How can I sort a list of strings in Dart?