当前位置:网站首页>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;
}
边栏推荐
- Pytorch neural network construction template
- Manually implement a simple stack
- PR 2021 quick start tutorial, learn about the and functions of the timeline panel
- [hardware ten treasures catalogue] - reprinted from "hardware 100000 whys" (under continuous update ~ ~)
- One click shell to automatically deploy any version of redis
- js解决浮点数相乘精度丢失问题
- [hard ten treasures] - 1 [basic knowledge] classification of power supply
- Introduction to JVM stack and heap
- 神经网络-最大池化的使用
- Why is Internet thinking not suitable for AI products?
猜你喜欢

Sorting out 49 reports of knowledge map industry conference | AI sees the future with wisdom

【硬十宝典】——2.【基础知识】开关电源各种拓扑结构的特点

【硬十宝典】——1.【基础知识】电源的分类

Principle, technology and implementation scheme of data consistency in distributed database

C#读写应用程序配置文件App.exe.config,并在界面上显示
![[hard ten treasures] - 2 [basic knowledge] characteristics of various topological structures of switching power supply](/img/c2/6dfb9f477306edb46ff2a6a6ca32dd.png)
[hard ten treasures] - 2 [basic knowledge] characteristics of various topological structures of switching power supply

CF1638E. Colorful operations Kodori tree + differential tree array

Pytorch(三) —— 函数优化

Use of dataloader

分布式锁的实现
随机推荐
解决:Thread 1:[<*>setValue:forUndefinedKey]:this class is not key value coding-compliant for the key *
Shell之分析服务器日志命令集锦
【暑期每日一题】洛谷 P1629 邮递员送信(未完待续...)
Kodori tree board
C read / write application configuration file app exe. Config and display it on the interface
STM32 光敏电阻传感器&两路AD采集
STM32 photoresistor sensor & two channel AD acquisition
RuntimeError: mean(): input dtype should be either floating point or complex dtypes.Got Long instead
【暑期每日一题】洛谷 P7222 [RC-04] 信息学竞赛
RuntimeError: mean(): input dtype should be either floating point or complex dtypes. Got Long instead
[FTP] the solution to "227 entering passive mode" during FTP connection
pytorch中常用数据集的使用方法
PR 2021 quick start tutorial, learn about the and functions of the timeline panel
This sideline workload is small, 10-15k, free unlimited massage
Shell之Unix运维常用命令
Openresty rewrites the location of 302
【暑期每日一題】洛穀 P1568 賽跑
字符输入流与字符输出流
Neural network convolution layer
Solve the problem that the external chain file of Qiankun sub application cannot be obtained