HDU6061 RXD and functions

Description

已知 $f(x) = \sum\limits_{i=0}^{n}c_ix^i$ ,求 $g(x) = f(x+a) = \sum\limits_{i=0}^{n} c_i(x+a)^i$ 的各项系数。

Solution

hdu6061

(写了半天的公式忘保存还好我留了一张图片)

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <bits/stdc++.h>

using namespace std;

const int N = (int)1e5 + 10;
const int mod = 998244353;
const int G = 3;

int n, c[N], rev[1 << 21], fac[N];

int fpw(int x, int k, int p) {
int ret = 1;
while(k) {
if(k & 1) ret = 1ll * ret * x % p;
x = 1ll * x * x % p; k >>= 1;
} return ret;
}

int add(int x, int y) {
return (x += y) >= mod ? x - mod : x;
}

void NTT(int *a, int L, int op) {
for(int i = 0; i < L; i++)
if(i < rev[i]) swap(a[i], a[rev[i]]);
for(int i = 1, l = 0; i < L; i <<= 1, l++) {
int w = fpw(G, (mod - 1) >> (l + 1), mod);
if(op == -1) w = fpw(w, mod - 2, mod);
for(int j = 0; j < L; j += (i << 1)) {
int wn = 1;
for(int k = j; k < i + j; k++) {
int t = (1ll * wn * a[i + k] % mod);
a[i + k] = add(a[k], mod - t);
a[k] = add(a[k], t);
wn = (1ll * wn * w) % mod;
}
}
}
if(op == -1) {
int invL = fpw(L, mod - 2, mod);
for(int i = 0; i < L; i++)
a[i] = (1ll * a[i] * invL % mod);
}
}

int f[1 << 21], g[1 << 21];

int main() {
fac[0] = 1;
for(int i = 1; i <= (int)1e5; i++)
fac[i] = 1ll * fac[i - 1] * i % mod;
while(scanf("%d", &n) != EOF) {
int A = 0;
for(int i = 0; i <= n; i++)
scanf("%d", &c[i]);
int L = 1, l = 0;
while(L <= 2 * (n + 1)) L <<= 1, l++;
for(int i = 0; i < L; i++)
rev[i] = ((rev[i >> 1] >> 1) | (i & 1) << (l - 1));
memset(f, 0, sizeof(int) * L);
memset(g, 0, sizeof(int) * L);
int m; scanf("%d", &m);
for(int i = 1; i <= m; i++) {
int t; scanf("%d", &t); A -= t; A %= mod;
} A = (A + mod) % mod;
for(int i = 0; i <= n; i++)
f[i] = 1ll * c[i] * fac[i] % mod,
g[n - i] = 1ll * fpw(A, i, mod) * fpw(fac[i], mod - 2, mod) % mod;
NTT(f, L, 1), NTT(g, L, 1);
for(int i = 0; i < L; i++)
f[i] = 1ll * f[i] * g[i] % mod;
NTT(f, L, -1);
for(int i = n; i <= 2 * n; i++) {
printf("%d ", 1ll * f[i] * fpw(fac[i - n], mod - 2, mod) % mod);
} putchar('\n');
}
return 0;
}