切不动了!!!
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;++i)
using namespace std;
inline int read(){int x=0;bool f=0;char ch=getchar();while (ch<'0'||ch>'9'){if (ch=='-') f=1;ch=getchar();}while (ch>='0'&&ch<='9'){x=x*10+ch-48;ch=getchar();}return f?-x:x;}
template<typename T>inline bool Max(T &a,T b){return a<b?a=b,1:0;}
template<typename T>inline bool Min(T &a,T b){return b<a?a=b,1:0;}
const int mod=998244353;
int T,n;
long long fac[2005],inv[2005],invfac[2005],bin[2005],g[2005];
void add(long long &a,long long b){a+=b;if(a>=mod) a-=mod;}
long long Pow(long long a,long long b){
long long res=1ll;
for(;b;b>>+1,a=a*a%mod) if(b&1) res=res*a%mod;
return res;
}
long long C(int n,int m){
return fac[n]*invfac[n-m]%mod*invfac[m]%mod;
}
int main(){
fac[0]=invfac[0]=inv[1]=bin[0]=1;
rep(i,1,2005-1){
if(i^1) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
fac[i]=fac[i-1]*i%mod;
invfac[i]=invfac[i-1]*inv[i]%mod;
bin[i]=bin[i-1]*2%mod;
}
g[0]=1,g[1]=0;
rep(n,2,1000) g[n]=4ll*n*(n-1)%mod*(g[n-1]+2*(n-1)*g[n-2])%mod;
T=gi();
while(T--){
n=gi();
rep(k,0,n) printf("%lld\n",C(n,k)*C(n,k)%mod*fac[k]%mod*bin[k]%mod*g[n-k]%mod);
}
return 0;
}
同理:
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;++i)
using namespace std;
inline int read(){int x=0;bool f=0;char ch=getchar();while (ch<'0'||ch>'9'){if (ch=='-') f=1;ch=getchar();}while (ch>='0'&&ch<='9'){x=x*10+ch-48;ch=getchar();}return f?-x:x;}
template<typename T>inline bool Max(T &a,T b){return a<b?a=b,1:0;}
template<typename T>inline bool Min(T &a,T b){return b<a?a=b,1:0;}
const int mod=998244353,big=5e6+5;
int T,n,k;
long long fac[big],inv[big],invfac[big],bin[big],g[big];
void add(long long &a,long long b){a+=b;if(a>=mod) a-=mod;}
long long Pow(long long a,long long b){
long long res=1ll;
for(;b;b>>+1,a=a*a%mod) if(b&1) res=res*a%mod;
return res;
}
long long C(int n,int m){
return fac[n]*invfac[n-m]%mod*invfac[m]%mod;
}
int main(){
fac[0]=invfac[0]=inv[1]=bin[0]=1;
rep(i,1,big-1){
if(i^1) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
fac[i]=fac[i-1]*i%mod;
invfac[i]=invfac[i-1]*inv[i]%mod;
bin[i]=bin[i-1]*2%mod;
}
g[0]=1,g[1]=0;
rep(n,2,big-3) g[n]=4ll*n*(n-1)%mod*(g[n-1]+2*(n-1)*g[n-2])%mod;
T=read();
while(T--){
n=read();k=read();
printf("%lld\n",C(n,k)*C(n,k)%mod*fac[k]%mod*bin[k]%mod*g[n-k]%mod);
}
return 0;
}
标签:return,invfac,int,long,P4931,P4921,fac,mod
From: https://www.cnblogs.com/zan-mei-tai-yang/p/18493685