当前位置:网站首页>卢卡斯定理
卢卡斯定理
2022-07-15 22:41:00 【一条小小yu】
#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
long long n,m,p;
long long quickpow(long long base,long long power){
long long ret=1;
while(power){
if(power%2)
ret=ret*base%p;
base=base*base%p;
power/=2;
}
return ret;
}
long long C(long long n,long long m){
if(n<m) return 0;
if(m>n-m) m=n-m;
long long a=1,b=1;
for(int i=0;i<m;i++){
a=(a*(n-i))%p;
b=(b*(i+1))%p;
}
return a*quickpow(b,p-2)%p;
}
long long Lucas(long long n,long long m){
if(m==0) return 1;
return Lucas(n/p,m/p)*C(n%p,m%p)%p;
}
int main()
{
int T;
scanf("%d",&T);
while(T--){
scanf("%lld%lld%lld",&n,&m,&p);
printf("%lld\n",Lucas(n,m));
}
return 0;
}
边栏推荐
- Reinforcement learning (I)
- Uni app - solve the problem that rich text parsing pictures cannot adapt to width and height (pictures exceed the screen width and are uncontrolled)
- 时间模块之datatime模块、os模块、sys模块、json模块、json模块实操
- 解决Google colab上安装GPU版本mxnet报错:libnvrtc.so.11.2: cannot open shared object file: No such file...
- Tagger: Deep Unsupervised Perceptual Grouping
- 金融行业开放平台
- Heartless sword Chinese translation of Michael's definition of algebra
- Cloud computing in China: prospects for 2025
- Maxwell配置案例
- SQL基础(一):安装MySQL以及一些简单操作
猜你喜欢

Reinforcement learning (II)

Heartless sword Chinese translation of Michael's definition of algebra

Acl+ant comprehensive case (7.15)

力扣练习——15 接雨水
[email protected] | Metal organic framework complex uio-66-nh2/mos2|pps-zif-8-bsa|pva/uio-66| [email protected] |

Ten minute quick learning flash framework

五种常见的加密方式及常用的加解密工具

Model comparison of material inventory management between sap ECC and s4hana material
![[paper reading | deep reading] graph neural networks with local structural patterns](/img/6b/46be283fa4f36c634f0c19f9cebd5d.png)
[paper reading | deep reading] graph neural networks with local structural patterns

LeetCode_ 513_ Find the value in the lower left corner of the tree
随机推荐
NC19910 [CQOI2007]矩形RECT
datagridview最后一列自动扩展到剩余部分
Heartless sword Chinese translation of Michael's definition of algebra
Cloud computing in China: prospects for 2025
Thinking about the research links of data governance projects
Zabbix+mysql fpmmm (MPM) monitoring
十分钟快速学习flask框架
JVM fatal error log (hs_err_pid.log) interpretation
LeetCode_513_找树左下角的值
ACL+ANT综合案例(7.15)
PHP版本新特性摘选 - PHP7.2.x 到 PHP7.4.x
0715-铁矿石跌10%
漫谈软件缺陷管理的价值
ACL访问控制列表案例(7.15)
金融行业开放平台
Li Kou daily question - day 38 -58 Length of the last word
Execution plan of SQL statement
多御安全浏览器怎么移除密码?
2022-7-11 pcl double free or corruption(out) . valgrind. -march=native
[558. Intersection of quadtrees]