【bzoj2982】combination
来源:互联网 发布:淘宝o2o平台 编辑:程序博客网 时间:2024/04/30 17:20
Lucas定理裸题。
设
则
预处理出阶乘的模和阶乘的模的逆,直接计算。
#include <bits/stdc++.h>#define rep(i,a,b) for(int i=a;i<=b;i++)#define per(i,a,b) for(int i=a;i>=b;i--)inline int rd() { char c = getchar(); while (!isdigit(c)) c = getchar() ; int x = c - '0'; while (isdigit(c = getchar())) x = x * 10 + c - '0'; return x;}const int mod = 10007;typedef int arr[mod + 10];arr invF , fact;int n , m;inline int mul(int a , int b) { a *= b ; if (a >= mod) a %= mod ; return a ; }inline int Pow(int a , int b) { int t = 1; while (b) { if (b & 1) t = mul(t , a); a = mul(a , a) , b >>= 1; } return t;}void init() { fact[1] = 1; rep (i , 2 , mod - 1) fact[i] = mul(fact[i - 1] , i); invF[1] = 1; rep (i , 2 , mod - 1) invF[i] = mul(invF[i - 1] , Pow(i , mod - 2)); invF[0] = fact[0] = 1;}void input() { n = rd() , m = rd();}inline int _C(int n , int m) { if (n < m) return 0; return mul(fact[n] , mul(invF[n - m] , invF[m]));}void solve() { int t = 1; while (m) { t = mul(t , _C(n % mod , m % mod)); n = n / mod , m = m / mod; } printf("%d\n" , t);}int main() { #ifndef ONLINE_JUDGE // freopen("data.txt" , "r" , stdin); #endif init(); per (T , rd() , 1) { input(); solve(); } return 0;}
0 0
- 【bzoj2982】combination
- BZOJ2982: combination
- [bzoj2982]combination
- BZOJ2982 combination
- bzoj2982 combination
- 【bzoj2982】 combination LUCAS定理
- 【bzoj2982】【combination】【Lucas定理】
- BZOJ2982——combination
- 【lucas定理】BZOJ2982 combination
- BZOJ2982: combination(Lucas定理)
- Lucas定理模板【bzoj2982】【combination】
- bzoj2982: combination 组合数 卢卡斯定理
- [BZOJ2982]combination(组合数学lucas定理)
- 组合数学lucas定理 BZOJ2982 combination
- [bzoj2982]combination(组合数学lucas定理)
- bzoj2982 combination【Lacus定理+线性求逆元】
- bzoj2982 -- Lucas定理
- combination
- tomcat 多实例部署
- ZZULIOJ 1793 有趣的球
- 使用 PopupWindow 自定义对话框遭遇的悲催事件和解决方法
- 利用遍历思想求解图问题(输出一些简单回路)
- 字符串匹配(一)——朴素算法,Rabin-Karp算法
- 【bzoj2982】combination
- eclipse没有(添加)”Dynamic Web Project”选项的方法
- Spring @Transactional 到底是怎么工作的?
- 30.自定义UITableViewCell第一章
- 《Linux命令、编辑器与Shell编程》读书笔记4.3-其他数据文件处理命令(tr,sort,cut,paste,join,uniq,split)
- 2015 CCPC Ancient Go
- 2016 JAVA与Android面试题整理
- C#(WPF)按钮图片不显示,壁纸切换功能
- java集合