当前位置:网站首页>Find the combination number acwing 887 Find combination number III
Find the combination number acwing 887 Find combination number III
2022-07-05 06:23:00 【T_ Y_ F666】
Find the combination number AcWing 887. Find the combination number III
Original link
AcWing 887. Find the combination number III
Algorithm tags
Combinatorial mathematics Combination count Lucas Theorem Inverse element Fast power Fermat's small Theorem
Ideas
Code
#include<bits/stdc++.h>
#define int long long
#define abs fabs
#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 = 105;
double a[N][N], eps = 1e-8;
int 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;
}
int C(int a, int b, int p){
if(a<b){
return 0;
}else{
int res=1;
// for The loop only executes b Time , So it's from a Start riding b Number , namely a*(a-1)*…*(a-b+1), That's equal to a!/(a-b)!
for(int i=1, j=a; i<=b; ++i, --j){
res=res*j%p;
res=res*qmi(i, p-2, p)%p;
}
return res;
}
}
int lu(int a, int b, int p){
if(a<p&&b<p){
return C(a, b, p);
}else{
return C(a%p, b%p, p)*lu(a/p, b/p, p)%p;
}
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
n=read();
while(n--){
int a=read(), b=read(), p=read();
printf("%lld\n", lu(a, b, p));
}
}
Originality is not easy.
Reprint please indicate the source
If it helps you Don't forget to praise and support
边栏推荐
- LeetCode 1200. Minimum absolute difference
- 传统数据库逐渐“难适应”,云原生数据库脱颖而出
- 2.Oracle-数据文件的添加及管理
- 4. 对象映射 - Mapping.Mapster
- Matrixdb V4.5.0 was launched with a new mars2 storage engine!
- 11-gorm-v2-03-basic query
- Leetcode divide and conquer / dichotomy
- How to generate an image from text on fly at runtime
- 论文阅读报告
- Winter vacation water test 1 Summary
猜你喜欢
AE tutorial - path growth animation
Redis-01.初识Redis
MySQL怎么运行的系列(八)14张图说明白MySQL事务原子性和undo日志原理
Network security skills competition in Secondary Vocational Schools -- a tutorial article on middleware penetration testing in Guangxi regional competition
Alibaba's new member "Lingyang" officially appeared, led by Peng Xinyu, Alibaba's vice president, and assembled a number of core department technical teams
MySQL advanced part 2: SQL optimization
SQLMAP使用教程(二)实战技巧一
5.Oracle-表空间
Alibaba established the enterprise digital intelligence service company "Lingyang" to focus on enterprise digital growth
容斥原理 AcWing 890. 能被整除的数
随机推荐
20220213-CTF MISC-a_ good_ Idea (use of stegsolve tool) -2017_ Dating_ in_ Singapore
[rust notes] 16 input and output (Part 1)
[rust notes] 14 set (Part 1)
What is socket? Basic introduction to socket
Simple selection sort of selection sort
5. Oracle TABLESPACE
1.14 - assembly line
求组合数 AcWing 888. 求组合数 IV
Liunx starts redis
MySQL advanced part 2: MySQL architecture
How to set the drop-down arrow in the spinner- How to set dropdown arrow in spinner?
求组合数 AcWing 889. 满足条件的01序列
How to generate an image from text on fly at runtime
4. 对象映射 - Mapping.Mapster
Operator priority, one catch, no doubt
Redis-02.Redis命令
SPI 详解
Presentation of attribute value of an item
博弈论 AcWing 894. 拆分-Nim游戏
SQL三种连接:内连接、外连接、交叉连接