typedef long long ll; /********************************** 大组合数取模之lucas定理模板,1<=n<=m<=1e9,1<p<=1e6,p必须为素数 输入:C(n,m)%p 调用lucas(n,m,p) 复杂度:min(m,p)*log(m) ***********************************/ //ax + by = gcd(a,b) //传入固定值a,b.放回 d=gcd(a,b), x , y…
#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…
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int a[4]={2,3,4679,35617}; int p[36000],b[4],n,g,ans,i,j,x,y,mod=999911658; int power(int a,int b){//快速幂 int c=1; for(;b;b>>=1){ if(b&1) c=(ll)c*a%mod; a=(ll)a*a%mod;…
题集链接: 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…
题意:两匹马比赛有三种比赛结果,n匹马比赛的所有可能结果总数 解法: 设答案是f[n],则假设第一名有i个人,有C(n,i)种可能,接下来还有f(n-i)种可能性,因此答案为 ΣC(n,i)f(n-i) 另外这里给出两个求组合数的模板,卢卡斯定理的p是模数,并且要求是素数,第二个是递推式,适合于n<2000的情况 #include<cstdio> using namespace std; const int maxn = 1e3; ; typedef long long ll; /*--…
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…