题集链接: https://cn.vjudge.net/contest/231988 解题之前请先了解组合数取模和Lucas定理 A : FZU-2020 输出组合数C(n, m) mod p (1 <= m <= n <= 10^9, m <= 10^4, m < p < 10^9, p是素数) 由于p较大,不可以打表,直接Lucas求解 #include<iostream> using namespace std; typedef long long…
DP? Problem Description Figure 1 shows the Yang Hui Triangle. We number the row from top to bottom 0,1,2,…and the column from left to right 0,1,2,….If using C(n,k) represents the number of row n, column k. The Yang Hui Triangle has a regular pattern…
对于C(n, m) mod p.这里的n,m,p(p为素数)都很大的情况.就不能再用C(n, m) = C(n - 1,m) + C(n - 1, m - 1)的公式递推了. 这里用到Lusac定理 For non-negative integers m and n and a prime p, the following congruence relation holds: where and are the base p expansions of m and n respectively.…
#include<bits/stdc++.h> #define re register #define int long long using namespace std; ; inline int read(){ re ,b=;re char ch=getchar(); ') b=(ch==:,ch=getchar(); ') a=(a<<)+(a<<)+(ch^),ch=getchar(); return a*b; } inline int qpow(re int…
LL MyPow(LL a, LL b) { LL ret = ; while (b) { ) ret = ret * a % MOD; a = a * a % MOD; b >>= ; } return ret; } LL C(int n, int m) { ) ; LL a = fact[n], b = fact[n - m] * fact[m] % MOD; ) % MOD;//除以一个数,等于乘以这个数的乘法逆元, 然后是在MOD的情况下 } 上面的代码可以计算组合数取模, 能解决的规…