# Solution

$A(x)*B(x)\equiv 1\pmod {x^{\frac{n}{2}}}$
$A(x)*G(x)\equiv 1\pmod {x^n}$

$B(x)-G(x)\equiv 0\pmod {x^{\frac{n}{2}}}$

# Code

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>

typedef long long LL;
const int MOD=1004535809;
const int N=300005;
const int g=3;

LL rev[N],tmp[N],fac[N],ny[N],a[N],c[N],nc[N];
LL nyn;

LL ksm(LL x,LL dep) {
LL ret=1;
while (dep) {
if (dep&1) ret=ret*x%MOD;
x=x*x%MOD; dep/=2;
}
return ret;
}

void NTT(LL *a,int len,int f) {
int lg=log(len)/log(2)+0.1;
for (int i=0;i<len;i++) {
rev[i]=(rev[i/2]/2)|((i&1)<<(lg-1));
if (i<rev[i]) std:: swap(a[i],a[rev[i]]);
}
for (int i=1;i<len;i*=2) {
LL wn=ksm(g,(MOD-1)/i/2);
if (f==-1) wn=ksm(g,(MOD-1)-(MOD-1)/i/2);
for (int j=0;j<len;j+=i*2) {
LL w=1;
for (int k=0;k<i;k++) {
int u=a[j+k],v=a[j+i+k]*w%MOD;
a[j+k]=(u+v)%MOD; a[j+i+k]=(u-v+MOD)%MOD;
w=wn*w%MOD;
}
}
}
if (f==-1) {
LL nnyy=ksm(len,MOD-2);
for (int i=0;i<len;i++) a[i]=a[i]*nnyy%MOD;
}
}

void get_ny(LL *a,LL *b,int n) {
if (n==1) {
b[0]=ksm(a[0],MOD-2);
return ;
}
get_ny(a,b,n/2);
memcpy(tmp,a,sizeof(a[0])*n);
memset(tmp+n,0,sizeof(tmp[0])*n);
NTT(tmp,n*2,1); NTT(b,n*2,1);
for (int i=0;i<n*2;i++) tmp[i]=((LL)b[i]%MOD*(2-tmp[i]*b[i]%MOD+MOD)%MOD)%MOD;
NTT(tmp,n*2,-1);
for (int i=0;i<n;i++) b[i]=tmp[i];
memset(b+n,0,sizeof(b[0])*n);
}

int main(void) {
int n; scanf("%d",&n);
int len; for (len=1;len<=n;len*=2);
fac[0]=ny[0]=1;
for (int i=1;i<=n;i++) fac[i]=fac[i-1]*(LL)i%MOD,ny[i]=ksm(fac[i],MOD-2);
for (int i=0;i<=n;i++) c[i]=ksm(2,((LL)(i-1)*i/2)%(MOD-1))*ny[i]%MOD;
for (int i=1;i<=n;i++) a[i]=ksm(2,((LL)(i-1)*i/2)%(MOD-1))*ny[i-1]%MOD;
get_ny(c,nc,len);
NTT(a,len*2,1); NTT(nc,len*2,1);
for (int i=0;i<len*2;i++) a[i]=a[i]*nc[i]%MOD;
NTT(a,len*2,-1);
printf("%lld\n", a[n]*fac[n-1]%MOD);
return 0;
}


• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120