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 79 80 81 82 83 84 85 86 87 88
| #include <cstdio> #include <algorithm> using namespace std; template <class Type> void read (Type &x) { char c; bool flag = false; while ((c = getchar()) < '0' || c > '9') c == '-' && (flag = true); x = c - '0'; while ((c = getchar()) >= '0' && c <= '9') x = (x << 1) + (x << 3) + c - '0'; flag && (x = ~x + 1); } template <class Type, class ...rest> void read (Type &x, rest &...y) { read(x), read(y...); } template <class Type> void write (Type x) { x < 0 && (putchar('-'), x = ~x + 1); x > 9 && (write(x / 10), 0); putchar('0' + x % 10); } typedef long long LL; const int N = 5e5 + 10, mod = 1004535809; int rev[N]; int binpow (int b, int k = mod - 2) { int res = 1; for (; k; k >>= 1, b = (LL)b * b % mod) if (k & 1) res = (LL)res * b % mod; return res; } void ntt (int *x, int bit, int op) { int tot = 1 << bit; for (int i = 0; i < tot; ++i) if ((rev[i] = rev[i >> 1] >> 1 | (i & 1) << bit - 1) > i) swap(x[rev[i]], x[i]); for (int mid = 1, t = (mod - 1) >> 1; mid < tot; mid <<= 1, t >>= 1) { int w1 = binpow(3, ~op ? t : mod - 1 - t); for (int i = 0; i < tot; i += mid << 1) for (int j = 0, k = 1; j < mid; ++j, k = (LL)k * w1 % mod) { int p = x[i | j], q = (LL)k * x[i | mid | j] % mod; x[i | j] = (p + q) % mod, x[i | mid | j] = (p - q) % mod; } } if (~op) return; int itot = binpow(tot); for (int i = 0; i < tot; ++i) x[i] = (LL)x[i] * itot % mod; } void PolyMul (int n, int *f, int m, int *g, int nm, int *w) { int bit = 0; while (1 << bit < n + m - 1) ++bit; int tot = 1 << bit; for (int i = n; i < tot; ++i) f[i] = 0; for (int i = m; i < tot; ++i) g[i] = 0; ntt(f, bit, 1), ntt(g, bit, 1); for (int i = 0; i < tot; ++i) w[i] = (LL)f[i] * g[i] % mod; ntt(w, bit, -1); for (int i = nm; i < tot; ++i) w[i] = 0; } int main () { int n, k = 0, op; read(n); char c; while ((c = getchar()) < '0' || c > '9'); k = c - '0'; while ((c = getchar()) >= '0' && c <= '9') k = (k * 10ll + c - '0') % mod; read(op); static int A[N], B[N]; for (int i = 0; i < n; ++i) read(A[i]); B[0] = 1; for (int i = 1; i < n; ++i) B[i] = (LL)B[i - 1] * binpow(i) % mod * (op ? -(k - i + 1) : k + i - 1) % mod; PolyMul(n, A, n, B, n, A); for (int i = 0; i < n; ++i) write((A[i] + mod) % mod), putchar(' '); return 0; }
|