题意:中文题。

析:直接运用Lucas定理即可。但是FZU好奇怪啊,我开个常数都CE,弄的工CE了十几次,在vj上还不显示。

代码如下:

  1. #pragma comment(linker, "/STACK:1024000000,1024000000")
  2. #include <cstdio>
  3. #include <string>
  4. #include <cstdlib>
  5. #include <cmath>
  6. #include <iostream>
  7. #include <cstring>
  8. #include <set>
  9. #include <queue>
  10. #include <algorithm>
  11. #include <vector>
  12. #include <map>
  13. #include <cctype>
  14. #include <cmath>
  15. #include <stack>
  16. //#include <unordered_map>
  17. //#include <tr1/unordered_map>
  18. //#define freopenr freopen("in.txt", "r", stdin)
  19. //#define freopenw freopen("out.txt", "w", stdout)
  20. using namespace std;
  21. //using namespace std :: tr1;
  22.  
  23. typedef long long LL;
  24. typedef pair<int, int> P;
  25. const int INF = 0x3f3f3f3f;
  26. //const double inf = 0x3f3f3f3f3f3f;
  27. //const LL LNF = 0x3f3f3f3f3f3f;
  28. const double PI = acos(-1.0);
  29. const double eps = 1e-8;
  30. const int maxn = 10005;
  31. //const LL mod = 10000000000007;
  32. const int N = 1e6 + 5;
  33. const int dr[] = {-1, 0, 1, 0, 1, 1, -1, -1};
  34. const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1};
  35. const char *Hex[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
  36. inline LL gcd(LL a, LL b){ return b == 0 ? a : gcd(b, a%b); }
  37. int n, m;
  38. const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  39. const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  40. inline int Min(int a, int b){ return a < b ? a : b; }
  41. inline int Max(int a, int b){ return a > b ? a : b; }
  42. inline LL Min(LL a, LL b){ return a < b ? a : b; }
  43. inline LL Max(LL a, LL b){ return a > b ? a : b; }
  44. inline bool is_in(int r, int c){
  45. return r >= 0 && r < n && c >= 0 && c < m;
  46. }
  47. LL p;
  48.  
  49. LL quick_pow(LL a, LL n){
  50. LL ans = 1;
  51. a %= p;
  52. while(n){
  53. if(n & 1) ans = ans * a % p;
  54. a = a * a % p;
  55. n >>= 1;
  56. }
  57. return ans;
  58. }
  59.  
  60. LL C(LL n, LL m){
  61. if(n < m) return 0;
  62. LL a = 1, b = 1;
  63. while(m){
  64. a = a * n % p;
  65. b = b * m % p;
  66. --m; --n;
  67. }
  68. return a * quick_pow(b, p-2) % p;
  69. }
  70.  
  71. LL Lucas(LL n, LL m){
  72. if(!m) return 1;
  73. return C(n%p, m%p) * Lucas(n/p, m/p);
  74. }
  75.  
  76. int main(){
  77. int T; cin >> T;
  78. while(T--){
  79. LL n, m;
  80. scanf("%I64d %I64d %I64d", &n, &m, &p);
  81. printf("%I64d\n", Lucas(n, m));
  82. }
  83. return 0;
  84. }

FZU 2020 组合 (Lucas定理)的更多相关文章

  1. 快速求排列组合 lucas定理

    对于C(n, m) mod p.这里的n,m,p(p为素数)都很大的情况. 就不能再用C(n, m) = C(n - 1,m) + C(n - 1, m - 1)的公式递推了. 一般lucas定理的p ...

  2. FZU 2020 :组合 【lucas】

    Problem Description 给出组合数C(n,m), 表示从n个元素中选出m个元素的方案数.例如C(5,2) = 10, C(4,2) = 6.可是当n,m比较大的时候,C(n,m)很大! ...

  3. 组合 Lucas定理

    组合 Time Limit: 1000MS   Memory Limit: 32768KB   64bit IO Format: %I64d & %I64u [Submit]   [Go Ba ...

  4. FZU 2020 组合

    组合数求模要用逆元,用到了扩展的欧几里得算法. #include<cstdio> int mod; typedef long long LL; void gcd(LL a,LL b,LL ...

  5. 【Lucas组合数定理】组合-FZU 2020

    组合 FZU-2020 题目描述 给出组合数C(n,m), 表示从n个元素中选出m个元素的方案数.例如C(5,2) = 10, C(4,2) = 6.可是当n,m比较大的时候,C(n,m)很大!于是x ...

  6. lucas定理 FOJ 2020 组合

     Problem 2020 组合 Accept: 886    Submit: 2084Time Limit: 1000 mSec    Memory Limit : 32768 KB Problem ...

  7. Bzoj 4591: [Shoi2015]超能粒子炮·改 数论,Lucas定理,排列组合

    4591: [Shoi2015]超能粒子炮·改 Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 178  Solved: 70[Submit][Stat ...

  8. 【BZOJ4591】超能粒子炮·改(Lucas定理,组合计数)

    题意: 曾经发明了脑洞治疗仪&超能粒子炮的发明家SHTSC又公开了他的新发明:超能粒子炮·改--一种可以发射威力更加 强大的粒子流的神秘装置.超能粒子炮·改相比超能粒子炮,在威力上有了本质的提 ...

  9. 【BZOJ4403】序列统计(Lucas定理,组合计数)

    题意:给定三个正整数N.L和R, 统计长度在1到N之间,元素大小都在L到R之间的单调不降序列的数量. 输出答案对10^6+3取模的结果. 对于100%的数据,1≤N,L,R≤10^9,1≤T≤100, ...

随机推荐

  1. BZOJ3126: [Usaco2013 Open]Photo

    n<=200000个点,m<=100000个区间,每个区间有且仅有一个点,求最多几个点,无解-1. http://www.cnblogs.com/Chorolop/p/7570191.ht ...

  2. PHP 基础复习 2018-06-21

    (1)PHP Zip File 函数 $zip = zip_open("test.zip"); if ($zip) { while ($zip_entry = zip_read($ ...

  3. 大数c++模板 超级好用

    只用输入用cin 输出  cout  每个数学符号都可以用   超级强大 #include <iostream> #include <queue> #include <c ...

  4. uva 1364

    刘书上例题 #include <cstdio> #include <cstdlib> #include <cmath> #include <set> # ...

  5. Access to Image at 'file:///Users canvas本地图片跨域报错解决方案

    1.设置跨域 添加跨域条件   crossorigin="anonymous" 前提是后端支持这个图片跨域 2.上面加了之后还是报错 如标题所示 你需要把你的项目放到服务器上面跑 ...

  6. Angular团队公布路线图,并演示怎样与React Native集成

    本文来源于我在InfoQ中文站翻译的文章,原文地址是:http://www.infoq.com/cn/news/2015/06/angular-2-react-native-roadmap 前不久在旧 ...

  7. 火狐浏览器Firefox 如何使用iMacros 自动填写网页表单

    1 我们首先访问一个想要自动填写表单的网站.我们以百度为例,右侧有登录窗口.   2 然后我们点开刚安装上的iMacros插件,一般安装之后就会自动出现在浏览器的某个地方,点击记录选项卡,再点击记录. ...

  8. Pacemaker 安装与使用

    Pacemaker 仅仅做资源管理器(CRM).底下的消息系统採用 corosync. 安装 以 ubuntu 为例, sudo aptitude install -y pacemaker coros ...

  9. python手记(53)

    import sys import pygame from pygame.locals import * import time import math pygame.init() screen=py ...

  10. 关于Scrum

    最近某些产品经理发出下两周的工作计划的时候,喜欢带上sprint这个字眼,看上去貌似是要走敏捷开发这一套,只可惜,我觉得他表现出来的是对敏捷开发和Scrum一窍不通,甚至对软件开发流程都完全不清楚,居 ...