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=( ...
随机推荐
- ScrollView嵌套StackView提示需要宽度和高度限制
场景: 在一个xib的view中,添加一个ScrollView,再在这个ScrollView中添加一个StackView,StackView中不加控件(用代码动态加). 问题: 提示ScrollVie ...
- plot a critical difference diagram , MATLAB code
plot a critical difference diagram , MATLAB code 建立criticaldifference函数 function cd = criticaldiffer ...
- Snappy压缩
Snappy压缩时,碰到不能解压问题,所用服务器Tomcat8.经验证,降低Tomcat版本为7,才可正常解压文件. 若碰到偶尔不能解压的问题,试着换个浏览器试试.
- BZOJ3996 [TJOI2015]线性代数
就是求$D = A \times B \times A^T - C \times A^T$ 展开也就是$$D = \sum_{i, j} A_i * A_j * B_{i, j} - \sum_{i} ...
- NodeJS无所不能:细数10个令人惊讶的NodeJS开源项目
在几年的时间里,NodeJS逐渐发展成一个成熟的开发平台,吸引了许多开发者.有许多大型高流量网站都采用NodeJS进行开发,像PayPal,此外,开发人员还可以使用它来开发一些快速移动Web框架. 除 ...
- 一模 (3) day2
第一题: 题目大意:和day1一样,给出m个小于n的数,求出出现次数大于m div 2 的数. 数据范围加大,1<=n<=2^31 1<=m<=3000000 解题过程: ...
- C- struct的使用
数组是二等公民,不能进行整体赋值,或者参数传递,或者作为返回值. But!如果封装在struct内部,就完全不一样了 #include <iostream> using namespace ...
- Spring学习笔记之整合struts
1.现有项目是通过 <action path="/aaaaAction" type="org.springframework.w ...
- DotNetBar v12.7.0.2 Fully Cracked
更新信息: http://www.devcomponents.com/customeronly/releasenotes.asp?p=dnbwf&v=12.7.0.2 如果遇到破解问题可以与我 ...
- SrcollView分页加载数据(MainActivity)
package com.baidu.mylistscroll; import java.util.ArrayList;import java.util.List; import com.baidu.a ...