我中间有一步没开LongLong,然后快速幂的时候就GG了
大概就是:
#include
#include
#include
#include
#include
#include
#define LL long long
using namespace std;
inline int read(){
int x=0,f=1;char ch=' ';
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
return x*f;
}
const int N=5e5+5,mod=1004535809,g=3,gi=334845270;
inline LL ksm(LL a,LL n){
LL ans=1LL;
while(n){
if(n&1)ans=ans*a%mod;
a=a*a%mod;
n>>=1;
}
return ans;
}
int n,R[N],m,bin[1<<23];
LL f[N],ans[N],h[N],tmp[N],inv_h[N],fac[N],inv[N],ifac[N],C[N];
inline void NTT(LL *a,int n,int f){
int L=bin[n];
for(int i=0;i>1]>>1)|((i&1)<<(L-1));
for(int i=0;iif(ifor(int i=1;i1){
LL wn=ksm(f==1?g:gi,(mod-1)/(i<<1));
for(int j=0;j1)){
LL w=1LL;
for(int k=0;kif(f==-1)for(int i=0;i2)%mod;
}
inline void poly_inv(LL *a,LL *b,int n){
if(n==1){b[0]=ksm(a[0],mod-2);return;}
poly_inv(a,b,(n+1)>>1);
int m=1;
for(;m<(n<<1);m<<=1);
for(int i=0;ifor(int i=n;i0;
NTT(tmp,m,1);NTT(b,m,1);
for(int i=0;i2LL*b[i]%mod-tmp[i]*b[i]%mod*b[i]%mod+mod)%mod;
NTT(b,m,-1);
for(int i=n;i0;
return;
}
int main(){
for(int i=0;i<22;++i)bin[1<0]=ifac[0]=inv[0]=inv[1]=1;
for(int i=1;i<=n;++i)fac[i]=fac[i-1]*i%mod;
for(int i=2;i<=n;++i)inv[i]=(mod-mod/i)*inv[mod%i]%mod;
for(int i=1;i<=n;++i)ifac[i]=ifac[i-1]*inv[i]%mod;
for(int i=1;i<=n;++i)C[i]=(LL)i*(i-1)/2%(mod-1);
for(int i=1;i<=n;++i)f[i]=ksm(2LL,C[i])*ifac[i-1]%mod;
for(int i=0;i<=n;++i)h[i]=ksm(2LL,C[i])*ifac[i]%mod;
for(m=1;m<=n;m<<=1);
poly_inv(h,inv_h,n+1);
NTT(f,m,1);NTT(inv_h,m,1);
for(int i=0;i1);
printf("%lld",ans[n]*fac[n-1]%mod);
return 0;
}