2018.09.14 bzoj2982: combination(Lucas定理)
传送门
貌似就是lucas的板子题啊。
练一练手感觉挺舒服的^_^
代码:
#include<bits/stdc++.h>
#define mod 10007
#define ll long long
using namespace std;
int T_T;
ll n,m,fac[mod+5],ifac[mod+5];
inline ll lucas(ll a,ll b){
if(a<b)return 0;
if(a<mod&&b<mod)return fac[a]*ifac[b]%mod*ifac[a-b]%mod;
return lucas(a%mod,b%mod)*lucas(a/mod,b/mod)%mod;
}
int main(){
scanf("%d",&T_T),fac[0]=1,ifac[1]=ifac[0]=1;
for(ll i=1;i<mod;++i)fac[i]=fac[i-1]*i%mod;
for(ll i=2;i<mod;++i)ifac[i]=(mod-mod/i)*ifac[mod%i]%mod;
for(ll i=2;i<mod;++i)(ifac[i]*=ifac[i-1])%=mod;
while(T_T--)scanf("%lld%lld",&n,&m),printf("%lld\n",lucas(n,m));
return 0;
}
2018.09.14 bzoj2982: combination(Lucas定理)的更多相关文章
- bzoj2982: combination(lucas定理板子)
2982: combination Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 664 Solved: 397[Submit][Status][Di ...
- [BZOJ2982]combination Lucas定理
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2982 $C(N,M)\% P = C(N\% P,M\% P) * C(N/P,M/P)\ ...
- 【BZOJ2982】combination Lucas定理
[BZOJ2982]combination Description LMZ有n个不同的基友,他每天晚上要选m个进行[河蟹],而且要求每天晚上的选择都不一样.那么LMZ能够持续多少个这样的夜晚呢?当然, ...
- ZOJ 3557 & BZOJ 2982 combination[Lucas定理]
How Many Sets II Time Limit: 2 Seconds Memory Limit: 65536 KB Given a set S = {1, 2, ..., n}, n ...
- BZOJ2982: combination Lucas模板
2982: combination Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 734 Solved: 437[Submit][Status][Di ...
- bzoj2982 combination——卢卡斯定理
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2982 卢卡斯定理裸题: 原准备1A来着,结果输出忘了加回车! 预处理阶乘或者现求都可以,感觉 ...
- BZOJ2982: combination Lucas
Description LMZ有n个不同的基友,他每天晚上要选m个进行[河蟹],而且要求每天晚上的选择都不一样.那么LMZ能够持续多少个这样的夜晚呢?当然,LMZ的一年有10007天,所以他想知道答案 ...
- BZOJ 2982 combination Lucas定理
题目大意:发上来就过不了审核了--总之大意就是求C(n,m) mod 10007 m,n∈[1,2*10^8] 卢卡斯定理:C(n,m)=C(n%p,m%p)*C(n/p,m/p) mod p 要求p ...
- 2018.09.14 洛谷P3931 SAC E#1 - 一道难题 Tree(树形dp)
传送门 简单dp题. f[i]表示以i为根的子树被割掉的最小值. 那么有: f[i]=min(∑vf[v],dist(i,fa))" role="presentation" ...
随机推荐
- leetcode118
public class Solution { public IList<IList<int>> Generate(int numRows) { var list = new ...
- Mysql 游标使用
BEGIN #shopsId 商家ID #accountDay 10位日期 -- 定义一个或者多个 变量来接收 游标查询的列值 DECLARE receiptContentId INT; -- 遍历数 ...
- 泛型集合与DataSet相互转换
一.泛型转DataSet /// <summary> /// 泛型集合转换DataSet /// </summary> /// <typeparam name=" ...
- Asp.Net Core参考资料
Every day up!!!!!! 1.Asp.Net官方文档 2.<Professional C# 6 and .NET Core 1.0> 翻译 3.ASP.NET Core中文文档 ...
- UIButton 点击事件传参数
#import <objc/runtime.h> UIButton *btn = // create the button objc_setAssociatedObject(btn, &q ...
- Technology, globalisation and the squeeze on good jobs
Technology, globalisation and the squeeze on good jobs技术与全球化冲击好工作“Highest stock market EVER! Jobs ar ...
- python 学习备忘
list列表排序 def listdir(path): #返回一个排序后的目录list files=os.listdir(path) files.sort(key=lambda x:str(x[:-4 ...
- tflearn 实现DNN 全连接
https://github.com/tflearn/tflearn/blob/master/examples/others/recommender_wide_and_deep.py import n ...
- Spring工作原理与单例
最近看到spring管理的bean为单例的,当它与web容器整合的时候始终搞不太清除,就网上搜索写资料, Tomcat与多线程, servlet是多线程执行的,多线程是容器提供的能力. servlet ...
- 第七章 二叉搜索树(b3)BST:删除