BZOJ 2982 combination
lucas定理裸题。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 20050
#define mod 10007
using namespace std;
long long t,n,m,inv1[maxn],inv2[maxn];
long long f_pow(long long x,long long y)
{
long long ans=,base=x;
while (y)
{
if (y&) ans=(ans*base)%mod;
base=(base*base)%mod;
y>>=;
}
return ans%mod;
}
void get_table()
{
inv1[]=;inv2[]=;
for (long long i=;i<=;i++)
{
inv1[i]=inv1[i-]*i%mod;
inv2[i]=f_pow(inv1[i],mod-);
}
}
long long comb(long long n,long long m)
{
return inv1[n]*inv2[m]%mod*inv2[n-m]%mod;
}
long long lucas(long long n,long long m)
{
if (!m) return ;
return comb(n%mod,m%mod)*lucas(n/mod,m/mod)%mod;
}
int main()
{
get_table();
scanf("%lld",&t);
for (long long i=;i<=t;i++)
{
scanf("%lld%lld",&n,&m);
printf("%lld\n",lucas(n,m));
}
return ;
}
BZOJ 2982 combination的更多相关文章
- 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 ...
- BZOJ 2982: combination( lucas )
lucas裸题. C(m,n) = C(m/p,n/p)*C(m%p,n%p). ----------------------------------------------------------- ...
- bzoj——2982: combination
2982: combination Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 611 Solved: 368[Submit][Status][Di ...
- bzoj 2982 combination——lucas模板
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2982 明明是lucas定理裸题…… 非常需要注意C( )里 if ( n<m ) r ...
- 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 ...
- BZOJ 2982 combination 脑子+组合数学
可以发现,整个数列构成一个树形结构,并且是个完全二叉堆(小根堆). 并且这个堆的形态在给定$n$后是固定的,第1个位置上显然只能放1. 对子树的根来说,他自己是所分得的数集中最小的那个,所以从剩下$s ...
- BZOJ 2982: combination Lucas模板题
Code: #include<bits/stdc++.h> #define ll long long #define maxn 1000003 using namespace std; c ...
- 【BZOJ 2982】 2982: combination (卢卡斯定理)
2982: combination Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 510 Solved: 316 Description LMZ有n个 ...
- 【BZOJ】2982: combination(lucas定理+乘法逆元)
http://www.lydsy.com/JudgeOnline/problem.php?id=2982 少加了特判n<m return 0就wa了QAQ lucas定理:C(n, m)%p=( ...
随机推荐
- 加载图片、倒计时--Columbia项目总结
CSS3 居然会在隐藏显示的时候触发,真心太神奇了(在ff下是没有用的,在chrome下才阔以) 貌似我还是写了大循环,怎么样才能优化这个循环呢 加载图片:已经用到过好多次了↓ function lo ...
- #define && const
(1) 编译器处理方式不同 define宏是在预处理阶段展开. const常量是编译运行阶段使用. (2) 类型和安全检查不同 define宏没有类型,不做任何类型检查,仅仅是展开. const常量有 ...
- cycleInterpolator 循环加速器
CycleInterpolator Repeats the animation for a specified number of cycles. The rate of change follows ...
- uva 1631
1631 Locker A password locker with N digits, each digit can be rotated to 0-9 circularly. You can ro ...
- weblogic部署ssh2应用出现异常
一般在domains\your_Domain\bin\startWebLogic.cmd 中找到set CLASSPATH=%CLASSPATH%;%MEDREC_WEBLOGIC_CLASSPATH ...
- ANGULAR JS WATCH监听使用
ANGULAR 监听使用: 当angular数据模型发生变化时,我们需要如果需要根据他的变化触发其他的事件. $watch是一个scope函数,用于监听模型变化,当你的模型部分发生变化时它会通知你. ...
- IISExpress配置文件的一个坑
现象: 昨天在处理PBS系统问题的时候意外发现两个js错误(而同样的代码在同事机器上都没有问题),如下图. 图1 图2 图3 原因分析: 初步看起来是因为页面上没有id为'form1'的form和id ...
- ubuntu 软件安装的几种方法
说明:由于图形化界面方法(如Add/Remove... 和Synaptic Package Manageer)比较简单,所以这里主要总结在终端通过命令行方式进行的软件包安装.卸载和删除的方法. 一.U ...
- FloatingActionButton增强版,一个按钮跳出多个按钮--第三方开源--FloatingActionButton
FloatingActionButton项目在github上的主页:https://github.com/futuresimple/android-floating-action-button F ...
- [css3]搜索框focus时变长
结构: <form class="demo-a"> <input placeholder="Search" type="sea ...