当前位置:网站首页>Mathematical knowledge: finding combinatorial number III - finding combinatorial number
Mathematical knowledge: finding combinatorial number III - finding combinatorial number
2022-07-01 01:39:00 【Fight! Sao Nian!】
subject :AcWing 887. Find the combination number III
Given n Group inquiry , Each group is asked to give three integers a,b,p, among p Prime number , Please output Cbamod p Value .
Input format
The first line contains integers n.
Next n That's ok , Each line contains a set of a,b,p.
Output format
common n That's ok , Each line outputs a solution to the query .
Data range
1≤n≤20,
1≤b≤a≤1018,
1≤p≤105,
sample input :
3
5 3 7
3 1 5
6 4 13
sample output :
3
3
2
Topic analysis :
From the above formula, we can know that the combinatorial number can be decomposed into smaller combinatorial numbers , We can use the fast power to find the inverse , To find the number of combinations
#include <iostream>
using namespace std;
typedef long long LL;
int p;
int qmi(int a,int k,int p) // Find fast power
{
int res=1;
while(k)
{
if(k&1)res=(LL)res*a%p;
a=(LL)a*a%p;
k>>=1;
}
return res;
}
int C(int a,int b,int p) // Find the combination number
{
if(b>a)return 0;
int res=1;
for(int i=1,j=a;i<=b;i++,j--)
{
res=(LL)res*j%p;
res=(LL)res*qmi(i,p-2,p)%p;
}
return res;
}
int lucas(LL a,LL b,int p) // Lucas theorem
{
if(a<p&&b<p)return C(a,b,p);
else return (LL)C(a%p,b%p,p)*lucas(a/p,b/p,p)%p;
}
int main()
{
int n;
cin>>n;
while(n--)
{
LL a,b;
cin>>a>>b>>p;
cout<<lucas(a,b,p)<<endl;
}
return 0;
}
边栏推荐
- 直播商城源码,实现左右联动商品分类页面
- 远程办公如何保持高效协同,实现项目稳定增长 |社区征文
- opencv -- 笔记
- Institute of Microbiology, commonly used biochemical reactions in microbiological testing
- 图灵奖得主LeCun指明AI未来的出路在于自主学习,这家公司已踏上征途
- More pragmatic in business
- 3500 word summary: a complete set of skills that a qualified software testing engineer needs to master
- 【qt5-tab标签精讲】Tab标签及内容分层解析
- Gin configuration file
- 视频教程 | 长安链推出系列视频教程合集(入门)
猜你喜欢

Qt5 mvc: revealing the secrets of data visualization

After working for 6 years, let's take stock of the golden rule of the workplace where workers mix up

关于白盒测试,这些技巧你得游刃有余~

Unknown database connection database error

neo4j安装、运行以及项目的构建和功能实现

The argument type 'function' can't be assigned to the parameter type 'void function()‘

zabbix如何配置告警短信?(预警短信通知设置流程)

【qt5-tab标签精讲】Tab标签及内容分层解析

迪赛智慧数——其他图表(平行坐标图):2021年应届专业就业情况

PHP crawls data through third-party plug-ins
随机推荐
PHP crawls data through third-party plug-ins
【队列】933. Number of Recent Calls
What are the functions of soil microorganisms in microbial detection?
[Office PDF] PDF merging and splitting will free us from the functional limitations of paid software, OK
Unknown database连接数据库错误
【Qt5-基础篇_1】从0开始,德天老师和你一起学习——窗口简介
迪赛智慧数——其他图表(平行坐标图):2021年应届专业就业情况
短视频平台开发,依靠DrawerLayout实现侧滑菜单效果
使用 C# 创造 ASCII 艺术
Working for eight years as a programmer, but with a salary of three years after graduation, it's too late to be enlightened again
TypeError: Argument ‘angle‘ can not be treated as a double
Neo4j installation, operation, project construction and function realization
laravel+redis 生成订单号-当天从1开始自增
mysql数据库基础:流程控制
Complete software development process
直播商城源码,实现左右联动商品分类页面
Visual studio 2019 Download
Some essential differences
TypeError: Argument ‘angle‘ can not be treated as a double
视频教程 | 长安链推出系列视频教程合集(入门)