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
| #include<bits/stdc++.h> #define int long long using namespace std; template <class T> inline void read(T &res) { res = 0; bool flag = 0; char c = getchar(); while('0' > c || c > '9') { if(c == '-') flag = 1; c = getchar();} while('0' <= c && c <= '9') res = (res << 3) + (res << 1) + (c ^ 48), c = getchar(); if(flag) res = -res; } template <class T, class ...Arg> inline void read(T &res, Arg &...com){ read(res), read(com...);} template <class T> void write(T res) { if(res > 9) write(res / 10); putchar(res % 10 + '0'); } const int N = 1e7 + 5, mod = 1004535809; int n, m, s; int qpow(int x, int k) { int res = 1; while(k) { if(k & 1) res = x * res % mod; k >>= 1; x = x * x % mod; } return res; } int inv[N], p[N], a[N], b[N]; inline int C(int x, int y) { return p[x] * inv[y] % mod * inv[x - y] % mod; } inline void init() { inv[0] = inv[1] = 1, p[0] = p[1] = 1; for(int i = 2;i <= max(n, m);i ++) p[i] = p[i - 1] * i % mod, inv[i] = (mod - mod / i) * inv[mod % i] % mod; for(int i = 2;i <= max(n, m);i ++) inv[i] = inv[i] * inv[i - 1] % mod;
for(int i = 0;i <= min(m, n / s);i ++) { a[i] = C(m, i) * p[n] % mod * qpow(inv[s], i) % mod * inv[n - s * i] % mod * qpow(m - i, n - s * i) % mod * p[i] % mod; b[i] = (mod + (i & 1 ? -1 : 1) * inv[i]) % mod; } } int len, tot, bit, r[N]; inline void NTT(int x[], int op) { for(int i = 0;i < tot;i ++) if(i < r[i]) swap(x[i], x[r[i]]); for(int mid = 1, gn, len;mid < tot;mid <<= 1) { len = mid << 1; gn = qpow(3, (mod - 1) / len); if(~op) gn = qpow(gn, mod - 2); for(int i = 0;i < tot;i += len) for(int j = 0, g = 1, a, b;j < mid;j ++, g = g * gn % mod) { a = x[i + j], b = g * x[i + j + mid] % mod; x[i + j] = (a + b) % mod; x[i + j + mid] = (a - b + mod) % mod; } } if(~op) return ; op = qpow(tot, mod - 2); for(int i = 0;i < tot;i ++) x[i] = x[i] * op % mod; } int ans; signed main() { read(n, m, s); init(); len = min(m, n / s); tot = 1; while(tot <= len * 2 + 2) tot <<= 1, bit ++; for(int i = 0;i < tot;i ++) r[i] = (r[i >> 1] >> 1) | ((i & 1) << (bit - 1)); reverse(a, a + len + 1); NTT(a, 1), NTT(b, 1); for(int i = 0;i < tot;i ++) a[i] = a[i] * b[i] % mod; NTT(a, -1); reverse(a, a + len + 1); for(int i = 0, o;i <= len;i ++) read(o), ans = (ans + a[i] * o % mod * inv[i]) % mod; write(ans); return 0; }
|