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 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
| #include <bits/stdc++.h>
using namespace std; typedef long long ll;
int n, k;
namespace PolyTech { #define mod 950009857 #define g 7
static const int maxn = 4e+5 + 5; ll A[maxn], B[maxn], inv[maxn], tmp[maxn], tmp2[maxn]; ll tmp5[maxn]; int rev[maxn];
void init() { inv[1] = 1; for (int i = 2; i < maxn; ++i) inv[i] = inv[mod % i] * (mod - mod / i) % mod; } inline ll quick_power(ll base, ll index) { ll ret = 1; while (index) { if (index & 1) ret = ret * base % mod; index >>= 1; base = base * base % mod; } return ret; } void DFT(ll *arr, int typ, int n) { int N = 1, L = 0; while (N < n) N <<= 1, L++; for (int i = 0; i < N; ++i) rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << (L - 1)); for (int i = 0; i < N; ++i) if (i > rev[i]) swap(arr[i], arr[rev[i]]); for (int i = 2; i <= N; i <<= 1) { int m = (i >> 1); ll e = quick_power(g, (mod - 1) / i); if (typ == -1) e = quick_power(e, mod - 2); for (int j = 0; j < N; j += i) { ll w = 1; for (int k = 0; k < m; ++k) { ll t = arr[j + m + k] * w % mod; arr[j + m + k] = (arr[j + k] - t + mod) % mod; arr[j + k] = (arr[j + k] + t) % mod; w = w * e % mod; } } } if (typ == 1) return; ll inv = quick_power(N, mod - 2); for (int i = 0; i < N; ++i) arr[i] = arr[i] * inv % mod; } void Derivative(ll *arr, ll *res, int len) { for (int i = 1; i < len; ++i) res[i - 1] = i * arr[i] % mod; res[len] = res[len - 1] = 0; } void Intergral(ll *arr, ll *res, int len) { for (int i = 1; i < len; ++i) res[i] = arr[i - 1] * inv[i] % mod; res[0] = 0; } void Inversion(ll *arr, ll *res, int len) { if (len == 1) { res[0] = quick_power(arr[0], mod - 2); return; } Inversion(arr, res, len >> 1); int now = len << 1; for (int i = 0; i < len; ++i) tmp5[i] = arr[i]; for (int i = len; i < now; ++i) tmp5[i] = 0; DFT(tmp5, 1, now); DFT(res, 1, now); for (int i = 0; i < now; ++i) tmp5[i] = res[i] * (2ll - tmp5[i] * res[i] % mod + mod) % mod; DFT(tmp5, -1, now); for (int i = 0; i < len; ++i) res[i] = tmp5[i]; for (int i = len; i < now; ++i) res[i] = 0; } void Logarithmic(ll *arr, ll *res, int len) { memset(tmp, 0, sizeof tmp); memset(tmp2, 0, sizeof tmp); Derivative(arr, tmp, len); Inversion(arr, tmp2, len); DFT(tmp, 1, len << 1); DFT(tmp2, 1, len << 1); for (int i = 0; i < (len << 1); ++i) tmp[i] = tmp[i] * tmp2[i] % mod; DFT(tmp, -1, len << 1); Intergral(tmp, res, len); } ll tmp3[maxn], tmp4[maxn]; void Exponent(ll *arr, ll *res, int len) { if (len == 1) { res[0] = 1; return; } Exponent(arr, res, len >> 1); for (int i = 0; i < len; ++i) tmp3[i] = res[i]; Logarithmic(tmp3, tmp4, len); for (int i = 0; i < len; ++i) tmp4[i] = (arr[i] - tmp4[i] + mod) % mod; tmp4[0] = (tmp4[0] + 1) % mod; DFT(tmp3, 1, len << 1); DFT(tmp4, 1, len << 1); for (int i = 0; i < (len << 1); ++i) tmp3[i] = tmp3[i] * tmp4[i] % mod; DFT(tmp3, -1, (len << 1)); for (int i = 0; i < len; ++i) res[i] = tmp3[i]; memset(tmp3, 0, sizeof tmp); memset(tmp4, 0, sizeof tmp2); }
void solve() { init(); scanf("%d%d", &n, &k); int x; for (int i = 1; i <= k; ++i) { scanf("%d", &x); A[x] = inv[x]; } int m = 1; while (m <= n) m <<= 1; Exponent(A, B, m); ll fac = 1; for (int i = 1; i <= n; ++i, fac = fac * i % mod) { ll ret = B[i] * fac % mod; printf("%lld\n", ret); } } }
int main() { PolyTech::solve(); return 0; }
|