68粉,P1641 [SCOI2010] 生成字符串
代码:
#include <bits/stdc++.h>
#define int long long
#define Luogu return
#define _DEQUE_ 0
using namespace std;
const int mod=20100403;
int qpow(int a,int b){
int res=1;
while(b){
if(b&1){
res=res*a%mod;
}
a=a*a%mod;
b>>=1;
}
return res;
}
int f(int x){
int res=1;
for(int i=2;i<=x;i++){
res*=i;
res%=mod;
}
return res;
}
int C(int m,int n){
if(m<n)return 0;
return qpow(f(m),mod)*qpow(f(m-n),mod-2)%mod*qpow(f(n),mod-2)%mod;
}
int n,m;
signed main(){
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
ios::sync_with_stdio(0);
cin.tie(0);
cin>>n>>m;
cout<<(C(n+m,m)-C(n+m,m-1)+mod)%mod;
Luogu _DEQUE_;
}69粉,P3807 【模板】卢卡斯定理 / Lucas 定理
代码:
#include <bits/stdc++.h>
#define int long long
#define Luogu return
#define _DEQUE_ 0
using namespace std;
const int N=1e6+5;
int n,m,p,T,fv[N];
int qpow(int a,int b,int p){
int res=1;
while(b){
if(b&1){
res=res*a%p;
}
a=a*a%p;
b>>=1;
}
return res;
}
int f(int x){
return fv[x];
}
int C(int n,int m,int p){
if(m>n)return 0;
return f(n)*qpow(fv[m],p-2,p)%p*qpow(fv[n-m],p-2,p)%p;
}
int Lucas(int n,int m,int p){
if(m==0)return 1;
return C(n%p,m%p,p)*Lucas(n/p,m/p,p)%p;
}
signed main(){
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
ios::sync_with_stdio(0);
cin.tie(0);
cin>>T;
while(T--){
cin>>n>>m>>p;
fv[0]=1;
for(int i=1;i<=max(n+m,p);i++){
fv[i]=fv[i-1]*i;
fv[i]%=p;
}
cout<<Lucas(n+m,n,p)<<endl;
}
Luogu _DEQUE_;
}
70粉,P7322 「PMOI-4」排列变换
代码:
#include <bits/stdc++.h>
#define int long long
#define Luogu return
#define _DEQUE_ 0
using namespace std;
const int mod=998244353;
int qpow(int a,int b){
int res=1;
while(b){
if(b&1){
res=res*a%mod;
}
a=a*a%mod;
b>>=1;
}
return res;
}
int f(int x){
int res=1;
for(int i=2;i<=x;i++){
res*=i;
res%=mod;
}
return res;
}
int C(int m,int n){
if(m<n)return 0;
return qpow(f(m),mod)*qpow(f(m-n),mod-2)%mod*qpow(f(n),mod-2)%mod;
}
int n,m,res=2;
signed main(){
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
ios::sync_with_stdio(0);
cin.tie(0);
cin>>n>>m;
for(int i=1;i<=n+1;i++){
res*=i;
res%=mod;
}
int s=1;
for(int i=1;i<=n;i++){
s*=i;
s%=mod;
}
res=qpow(res,mod)*qpow(m+1,mod-2)%mod;
cout<<(res-s+mod)%mod;
Luogu _DEQUE_;
}