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
| #include <cstdio> using namespace std; typedef long long LL; 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 << 3) + (x << 1) + c - '0'; flag && (x = ~x + 1); } template <class Type> void write(Type x) { x < 0 && (putchar('-'), x = ~x + 1); x > 9 && (write(x / 10), 0); putchar(x % 10 + '0'); } const int N = 21, mod = 1e9 + 9; int cnt[1 << N]; void fwt(int *x, int bit, int op) { int tot = 1 << bit; for (int mid = 1; mid < tot; mid <<= 1) for (int i = 0; i < tot; i += mid << 1) for (int j = 0; j < mid; j++) (x[i + j + mid] += x[i + j] * op) %= mod; } int main() { static int bit, A[N][1 << N], B[N][1 << N], C[N][1 << N]; read(bit); for (int i = 0; i < 1 << bit; i++) cnt[i] = cnt[i >> 1] + (i & 1); for (int i = 0; i < 1 << bit; i++) read(A[cnt[i]][i]); for (int i = 0; i < 1 << bit; i++) read(B[cnt[i]][i]); for (int i = 0; i <= bit; i++) fwt(A[i], bit, 1), fwt(B[i], bit, 1); for (int i = 0; i <= bit; i++) for (int j = 0; i + j <= bit; j++) for (int k = 0; k < 1 << bit; k++) (C[i + j][k] += (LL)A[i][k] * B[j][k] % mod) %= mod; for (int i = 0; i <= bit; i++) fwt(C[i], bit, -1); for (int i = 0; i < 1 << bit; i++) write((C[cnt[i]][i] + mod) % mod), putchar(' '); return 0; }
|