【题解】 bzoj2982: combination (Lucas定理)
Solution
- 板子题
Code
//It is coded by ning_mew on 7.25
#include<bits/stdc++.h>
#define LL long long
using namespace std;
const LL MOD=10007;
int T;
LL A[MOD],B[MOD],n,m;
void pre(){
A[0]=B[0]=A[1]=B[1]=1;
for(int i=2;i<MOD;i++)B[i]=-(MOD/i)*B[MOD%i]%MOD;
for(int i=2;i<MOD;i++)A[i]=i*A[i-1]%MOD,B[i]=B[i]*B[i-1]%MOD;
return;
}
LL C(LL n,LL m){
if(m>n)return 0;
return A[n]*B[n-m]%MOD*B[m]%MOD;
}
LL Lucas(LL n,LL m){
if(m==0)return 1;
return Lucas(n/MOD,m/MOD)*C(n%MOD,m%MOD)%MOD;
}
int main(){
pre();
scanf("%d",&T);
for(int i=1;i<=T;i++){
scanf("%lld%lld",&n,&m);
printf("%lld\n",(Lucas(n,m)%MOD+MOD)%MOD);
}return 0;
}
博主蒟蒻,随意转载。但必须附上原文链接:http://www.cnblogs.com/Ning-Mew/,否则你会场场比赛暴0!!!
【题解】 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来着,结果输出忘了加回车! 预处理阶乘或者现求都可以,感觉 ...
- [NOIP模拟测试7]visit 题解(组合数学+CRT+Lucas定理)
Orz 因为有T的限制,所以不难搞出来一个$O(T^3)$的暴力dp 但我没试 据说有30分? 正解的话显然是组合数学啦 首先$n,m$可能为负,但这并没有影响, 我们可以都把它搞成正的 即都看作向右 ...
- 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 ...
- Lucas定理模板【bzoj2982】【combination】
(上不了p站我要死了,侵权度娘背锅) Description LMZ有n个不同的基友,他每天晚上要选m个进行[河蟹],而且要求每天晚上的选择都不一样.那么LMZ能够持续多少个这样的夜晚呢?当然,LMZ ...
随机推荐
- vue 开发依赖安装
安装element-ui yarn add element-ui --save 使用element-ui main.js import Vue from 'vue'; import ElementUI ...
- package-lock.json和package.json的作用
转自:https://www.cnblogs.com/cangqinglang/p/8336754.html package-lock.json的作用就是锁定安装依赖时包的版本,并且需要上传到git, ...
- java核心API学习
1:java.lang (Object.String.StringBuffer.Thread.System.ClassLoader.Class.Runtime.包装类等)
- [转帖]pfSense软路由系统的使用
图解pfSense软路由系统的使用(NAT功能) http://seanlook.com/2015/04/23/pfsense-usage/ 发表于 2015-04-23 | 更新于: 2015- ...
- java的强制类型转换
java强制类型转换 详细连接https://www.cnblogs.com/kuangwong/p/6198862.html 在Java项目的实际开发和应用中,常常需要用到将对象转为String这 ...
- python爬虫之Gerapy安装部署
原创北航大才:https://cuiqingcai.com/5006.html NULL:http://www.infosec-wiki.com/?p=432737
- freemarker 简单操作
操作字符串函数 1. substring(start,end)从一个字符串中截取子串 start:截取子串开始的索引,start必须大于等于0,小于等于end end: 截取子串的长度,end必须大于 ...
- vue之v-for使用说明
demo.html <!DOCTYPE html> <html lang="en" xmlns:v-bind="http://www.w3.org/19 ...
- Bootstrap之图片展示界面Demo2
代码:(使用模板引擎freemarker) <!DOCTYPE html> <html> <head> <title>图片</title> ...
- 一、MyCat的搭建
一.什么是mycat 简单直接点就是,MyCat其实就是一个数据库的中间件!一般我们都是app直接到数据库!有了MyCat以后,就是app到MyCat然后再访问数据库. mycat是个中间件,它负责连 ...