计数好题
容斥式子:发现只要每个钦定方案的贡献都考虑到再配上容斥系数就是对的
O(n^2)->O(n)
把麻烦的i=0,j=0特殊考虑下
剩下的,先把麻烦的东西化简干净
然后枚举一维i,剩下的二项式定理!!!!
#include<bits/stdc++.h>
#define reg register int
#define il inline
#define fi first
#define se second
#define mk(a,b) make_pair(a,b)
#define numb (ch^'0')
#define pb push_back
#define solid const auto &
#define enter cout<<endl
using namespace std;
typedef long long ll;
template<class T>il void rd(T &x){
char ch;x=;bool fl=false;
while(!isdigit(ch=getchar()))(ch=='-')&&(fl=true);
for(x=numb;isdigit(ch=getchar());x=x*+numb);
(fl==true)&&(x=-x);
}
template<class T>il void output(T x){if(x/)output(x/);putchar(x%+'');}
template<class T>il void ot(T x){if(x<) putchar('-'),x=-x;output(x);putchar(' ');}
template<class T>il void prt(T a[],int st,int nd){for(reg i=st;i<=nd;++i) ot(a[i]);putchar('\n');} namespace Miracle{
const int N=1e6+;
const int mod=;
int ad(int x,int y){
return (x+y)>=mod?x+y-mod:x+y;
}
int qm(int x,ll y){
int ret=;
while(y){
if(y&) ret=(ll)ret*x%mod;x=(ll)x*x%mod;y>>=;
}return ret;
}
int inv[N],jie[N];
int C(int n,int m){
if(n<||m<||n<m) return ;
return (ll)jie[n]*inv[m]%mod*inv[n-m]%mod;
}
int main(){
int n;rd(n);
ll ans=;
jie[]=;
for(reg i=;i<=n;++i) jie[i]=(ll)jie[i-]*i%mod;
inv[n]=qm(jie[n],mod-);
for(reg i=n-;i>=;--i) inv[i]=(ll)inv[i+]*(i+)%mod;
for(reg i=;i<=n;++i){
ans=ad(ans,(i+)&?mod-(ll)C(n,i)*qm(,(ll)n*(n-i)+i)%mod:(ll)C(n,i)*qm(,(ll)n*(n-i)+i)%mod);
}
ans=ans*%mod;
ll sum=;
ll base=;
for(reg i=;i<=n-;++i){
sum=ad(sum,(i+)&?mod-(ll)C(n,i)*ad(qm(ad(,mod-base),n),mod-qm(mod-base,n))%mod:(ll)C(n,i)*ad(qm(ad(,mod-base),n),mod-qm(mod-base,n))%mod);
base=base*%mod;
}
ans=(ans+sum*)%mod;
ot(ans);
return ;
} }
signed main(){
Miracle::main();
return ;
} /*
Author: *Miracle*
*/