# [COGS 2287][HZOI 2015]疯狂的机器人

## Description

$1\leq n\leq 100000$

## Solution

$Catalan$ 数的第 $i$ 项为 $C_i$

$A(x)=\sum_{i=0}^\infty \frac{[2\mid i]\cdot C_{\left\lfloor\frac{i}{2}\right\rfloor}}{i!}x^i$

## Code

#include <bits/stdc++.h>
using namespace std;
const int N = 4*100000, yzh = 998244353;

int n, inv[N+5], fac[N+5], ifac[N+5], a[N+5], len, R[N+5], L;

int quick_pow(int a, int b) {
int ans = 1;
while (b) {
if (b&1) ans = 1ll*ans*a%yzh;
b >>= 1, a = 1ll*a*a%yzh;
}
return ans;
}
void NTT(int *A, int o) {
for (int i = 0; i < len; i++) if (i < R[i]) swap(A[i], A[R[i]]);
for (int i = 1; i < len; i <<= 1) {
int gn = quick_pow(3, (yzh-1)/(i<<1)), x, y;
if (o == -1) gn = quick_pow(gn, yzh-2);
for (int j = 0; j < len; j += (i<<1)) {
int g = 1;
for (int k = 0; k < i; k++, g = 1ll*g*gn%yzh) {
x = A[j+k], y = 1ll*g*A[j+k+i]%yzh;
A[j+k] = (x+y)%yzh, A[j+k+i] = (x-y)%yzh;
}
}
}
}
int C(int n, int m) {return 1ll*fac[n]*ifac[m]%yzh*ifac[n-m]%yzh; }
void work() {
scanf("%d", &n); inv[0] = inv[1] = fac[0] = ifac[0] = 1;
for (int i = 1; i <= n; i++) fac[i] = 1ll*i*fac[i-1]%yzh;
for (int i = 2; i <= n+1; i++) inv[i] = -1ll*yzh/i*inv[yzh%i]%yzh;
for (int i = 1; i <= n; i++) ifac[i] = 1ll*inv[i]*ifac[i-1]%yzh;
for (int i = 0; i <= n; i += 2) a[i] = 1ll*C(i, i/2)*inv[i/2+1]%yzh*ifac[i]%yzh;
for (len = 1; len <= (n<<1); len <<= 1) ++L;
for (int i = 0; i < len; i++) R[i] = (R[i>>1]>>1)|((i&1)<<(L-1));
NTT(a, 1);
for (int i = 0; i < len; i++) a[i] = 1ll*a[i]*a[i]%yzh;
NTT(a, -1);
for (int i = 0, inv = quick_pow(len, yzh-2); i < len; i++)
a[i] = 1ll*a[i]*inv%yzh*fac[i]%yzh;
int ans = 0;
for (int i = 0; i <= n; i += 2)
(ans += 1ll*a[i]*C(n, i)%yzh) %= yzh;
printf("%d\n", (ans+yzh)%yzh);
}
int main() {work(); return 0; }
posted @ 2018-04-06 15:24  NaVi_Awson  阅读(118)  评论(0编辑  收藏