标签:while solution com ima names int() tmp long tar
题目传送门
分析:
直接膜拜大佬博客OrzOrzOrz
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<iostream>
#include<map>
#include<string>
#include<bitset>
#define maxn 1000005
#define MOD 998244353
using namespace std;
inline long long getint()
{
long long num=0,flag=1;char c;
while((c=getchar())<‘0‘||c>‘9‘)if(c==‘-‘)flag=-1;
while(c>=‘0‘&&c<=‘9‘)num=num*10+c-48,c=getchar();
return num*flag;
}
int n;
int fac[maxn],inv[maxn];
inline int ksm(int num,long long k)
{
int ret=1;
for(;k;k>>=1,num=1ll*num*num%MOD)if(k&1)ret=1ll*ret*num%MOD;
return ret;
}
inline int C(int p,int q)
{return 1ll*fac[p]*inv[q]%MOD*inv[p-q]%MOD;}
int main()
{
n=getint();
fac[0]=fac[1]=inv[0]=inv[1]=1;
for(int i=2;i<=n;i++)fac[i]=1ll*fac[i-1]*i%MOD;
for(int i=2;i<=n;i++)inv[i]=1ll*inv[MOD%i]*(MOD-MOD/i)%MOD;
for(int i=2;i<=n;i++)inv[i]=1ll*inv[i]*inv[i-1]%MOD;
long long ans=0;
for(int i=1;i<=n;i++)
{
int tmp=1ll*C(n,i)*ksm(ksm(3,1ll*i*n),MOD-2)%MOD*(ksm((MOD+1-ksm(ksm(3,n-i),MOD-2))%MOD,n)-1)%MOD;
if(i&1)ans=(ans-tmp+MOD)%MOD;
else ans=(ans+tmp)%MOD;
}
ans=MOD-1ll*ans*ksm(3,(1ll*n*n+1)%(MOD-1))%MOD;
for(int i=1;i<=n;i++)
{
int tmp=1ll*C(n,i)*ksm(3,i)%MOD*ksm(3,1ll*n*(n-i))%MOD;
if(i&1)ans=(ans+2ll*tmp)%MOD;
else ans=((ans-2ll*tmp)%MOD+MOD)%MOD;
}
printf("%lld\n",(ans+MOD)%MOD);
}
标签:while solution com ima names int() tmp long tar
原文地址:https://www.cnblogs.com/Darknesses/p/13252136.html