【题解】 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 ...
随机推荐
- 网站之.htaccess文件
Apache系统中的.htaccess文件(分布式配置文件)提供了针对目录改变配置的方法,也就是在一个特定的文件目录中放置一个包含指令的文件,以作用于此目录以及所有子目录.直白的说,.htaccess ...
- Redis教程(Windows)
安装 1)下载redis压缩包并 , 推荐地址:https://github.com/MSOpenTech/redis/releases Redis 支持 32 位和 64 位.这个需要根据你系统平 ...
- tomcat server.xml各个端口的作用
<Server port="8005" shutdown="SHUTDOWN"> <!-- port:指定一个端口,这个端口负责监听关闭Tom ...
- 【学亮IT手记】MySql行列转换案例
create table score( name ), math int, english int ); ,); ,); ,); ,); SHOW tables; SELECT * from scor ...
- Spring是如何校验XML的
首先来看下xml的一些概念: xml的schema里有namespace,可以给它起个别名.比如常见的spring的namespace: xmlns:mvc="http://www.spri ...
- Java语言中姐种遍历List的方法总结
遍历 List 的方法: 1. for 2. advanced for 3. Iterator 4. while 5. ListIterator List<E> list 1. for f ...
- python之路--内置模块02
一. namedtuple 命名元组->类似创建了一个类 from collections import namedtuple # 类 p = namedtuple("Point&qu ...
- linux ps命令用法
-A 列出所有的进程-w 显示加宽可以显示较多的资讯-au 显示较详细的资讯-aux 显示所有包含其他使用者的行程 -A 显示所有进程(等价于-e)(utility)-a 显示 ...
- SQL Server中的完全连接(full join)
一.建库和建表 create database scort use scort create table emp ( empno int primary key, ename ), sal int, ...
- Eclipse:报错Failed to read artifact descriptor for org.springframework.boot:spring-boot-autoconfigure:jar:2.1.2.
导入SVN下载的MAVEN项目时springboot报错: pom.xml文件报错 Failed to read artifact descriptor for org.springframework ...