所求即为:
\[\begin{aligned} f_t & = \sum\limits_{m = 0}^L \binom{L}{m} A^m [k \mid m - t] \\ & = \frac{1}{k} \sum\limits_{m = 0}^L \binom{L}{m} A^m \sum\limits_{i = 0}^{k - 1} \omega_k^{i(m - t)} \\ & = \frac{1}{k} \sum\limits_{i = 0}^{k - 1} \omega_k^{-it} \sum\limits_{m = 0}^L \binom{L}{m} A^m \\ & = \frac{1}{k} \sum\limits_{i = 0}^{k - 1} \omega_k^{-it} (I + A)^L \end{aligned} \]接下来是一个 IDFT 的模板,直接套 Bluestein's Algorithm 即可。
code
#include <bits/stdc++.h>
#define pb emplace_back
#define fst first
#define scd second
#define mkp make_pair
#define mems(a, x) memset((a), (x), sizeof(a))
using namespace std;
typedef long long ll;
typedef __int128 lll;
typedef double db;
typedef unsigned long long ull;
typedef long double ldb;
typedef pair<ll, ll> pii;
const int maxn = 500100;
const int G = 3, mod1 = 998244353, mod2 = 1004535809, mod3 = 469762049;
const lll M = (lll)mod1 * mod2 * mod3;
inline ll qpow(ll b, ll p, const int &mod) {
ll res = 1;
while (p) {
if (p & 1) {
res = res * b % mod;
}
b = b * b % mod;
p >>= 1;
}
return res;
}
const lll I0 = (M / mod1) * qpow((M / mod1) % mod1, mod1 - 2, mod1);
const lll I1 = (M / mod2) * qpow((M / mod2) % mod2, mod2 - 2, mod2);
const lll I2 = (M / mod3) * qpow((M / mod3) % mod3, mod3 - 2, mod3);
int n, K, L, X, Y, mod;
struct node {
int x, y, z;
node(int a = 0, int b = 0, int c = 0) : x(a), y(b), z(c) {}
inline int get() {
return (x * I0 + y * I1 + z * I2) % M % mod;
}
} pw[maxn >> 1];
inline node operator + (const node &a, const node &b) {
return node(a.x + b.x < mod1 ? a.x + b.x : a.x + b.x - mod1, a.y + b.y < mod2 ? a.y + b.y : a.y + b.y - mod2, a.z + b.z < mod3 ? a.z + b.z : a.z + b.z - mod3);
}
inline node operator - (const node &a, const node &b) {
return node(a.x < b.x ? a.x - b.x + mod1 : a.x - b.x, a.y < b.y ? a.y - b.y + mod2 : a.y - b.y, a.z < b.z ? a.z - b.z + mod3 : a.z - b.z);
}
inline node operator * (const node &a, const node &b) {
return node(1LL * a.x * b.x % mod1, 1LL * a.y * b.y % mod2, 1LL * a.z * b.z % mod3);
}
typedef vector<node> poly;
int r[maxn];
typedef vector<node> poly;
inline void NTT(poly &a, int op) {
int n = (int)a.size();
for (int i = 0; i < n; ++i) {
if (i < r[i]) {
swap(a[i], a[r[i]]);
}
}
for (int k = 1; k < n; k <<= 1) {
node wn(qpow(op == 1 ? G : qpow(G, mod1 - 2, mod1), (mod1 - 1) / (k << 1), mod1), qpow(op == 1 ? G : qpow(G, mod2 - 2, mod2), (mod2 - 1) / (k << 1), mod2), qpow(op == 1 ? G : qpow(G, mod3 - 2, mod3), (mod3 - 1) / (k << 1), mod3));
pw[0] = node(1, 1, 1);
for (int i = 1; i < k; ++i) {
pw[i] = pw[i - 1] * wn;
}
for (int i = 0; i < n; i += (k << 1)) {
auto i1 = a.begin() + i, i2 = a.begin() + i + k;
node *p = pw;
int j = 0;
while (j + 7 < k) {
node x = *i1, y = (*p) * (*i2);
*i1 = x + y;
*i2 = x - y;
x = *(++i1);
y = (*(++p)) * (*(++i2));
*i1 = x + y;
*i2 = x - y;
x = *(++i1);
y = (*(++p)) * (*(++i2));
*i1 = x + y;
*i2 = x - y;
x = *(++i1);
y = (*(++p)) * (*(++i2));
*i1 = x + y;
*i2 = x - y;
x = *(++i1);
y = (*(++p)) * (*(++i2));
*i1 = x + y;
*i2 = x - y;
x = *(++i1);
y = (*(++p)) * (*(++i2));
*i1 = x + y;
*i2 = x - y;
x = *(++i1);
y = (*(++p)) * (*(++i2));
*i1 = x + y;
*i2 = x - y;
x = *(++i1);
y = (*(++p)) * (*(++i2));
*(i1++) = x + y;
*(i2++) = x - y;
++p;
j += 8;
}
while (j < k) {
node x = *i1, y = (*p) * (*i2);
*i1 = x + y;
*i2 = x - y;
++j;
++i1;
++i2;
++p;
}
}
}
if (op == -1) {
node inv(qpow(n, mod1 - 2, mod1), qpow(n, mod2 - 2, mod2), qpow(n, mod3 - 2, mod3));
for (int i = 0; i < n; ++i) {
a[i] = a[i] * inv;
}
}
}
inline void conv(poly &a, poly &b) {
NTT(a, 1);
NTT(b, 1);
int n = (int)a.size();
for (int i = 0; i < n; ++i) {
a[i] = a[i] * b[i];
}
NTT(a, -1);
}
inline vector<int> mul(const vector<int> &a, const vector<int> &b) {
int n = (int)a.size() - 1, m = (int)b.size() - 1, k = 0;
while ((1 << k) <= n + m + 1) {
++k;
}
for (int i = 1; i < (1 << k); ++i) {
r[i] = (r[i >> 1] >> 1) | ((i & 1) << (k - 1));
}
poly A(1 << k), B(1 << k);
for (int i = 0; i <= n; ++i) {
A[i] = node(a[i], a[i], a[i]);
}
for (int i = 0; i <= m; ++i) {
B[i] = node(b[i], b[i], b[i]);
}
conv(A, B);
vector<int> res(n + m + 1);
for (int i = 0; i <= n + m; ++i) {
res[i] = A[i].get();
}
return res;
}
inline vector<int> bls(int n, int m, int w, vector<int> &a) {
static int pw[maxn], ipw[maxn];
pw[0] = pw[1] = ipw[0] = ipw[1] = 1;
int iw = qpow(w, mod - 2, mod);
for (int i = 2; i <= max(n, m) + 1; ++i) {
pw[i] = 1LL * pw[i - 1] * w % mod;
ipw[i] = 1LL * ipw[i - 1] * iw % mod;
}
for (int i = 2; i <= max(n, m) + 1; ++i) {
pw[i] = 1LL * pw[i - 1] * pw[i] % mod;
ipw[i] = 1LL * ipw[i - 1] * ipw[i] % mod;
}
vector<int> b(n + 1), c(n + m + 1);
for (int i = 0; i <= n + m; ++i) {
if (i <= n) {
b[i] = 1LL * a[i] * pw[i + 1] % mod;
}
c[i] = ipw[i >= n ? i - n : n - i + 1];
}
vector<int> d = mul(b, c), res(m + 1);
for (int i = 0; i <= m; ++i) {
res[i] = 1LL * pw[i] * d[i + n] % mod;
}
return res;
}
struct mat {
int a[3][3];
mat() {
mems(a, 0);
}
} a;
inline mat operator * (const mat &a, const mat &b) {
mat res;
for (int k = 0; k < n; ++k) {
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
res.a[i][j] = (res.a[i][j] + 1LL * a.a[i][k] * b.a[k][j]) % mod;
}
}
}
return res;
}
inline mat qpow(mat a, ll p) {
mat res;
for (int i = 0; i < n; ++i) {
res.a[i][i] = 1;
}
while (p) {
if (p & 1) {
res = res * a;
}
a = a * a;
p >>= 1;
}
return res;
}
inline bool check(int x) {
vector<int> vc;
int y = mod - 1;
for (int i = 2; i * i <= y; ++i) {
if (y % i == 0) {
vc.pb(i);
while (y % i == 0) {
y /= i;
}
}
}
if (y > 1) {
vc.pb(y);
}
for (int t : vc) {
if (qpow(x, (mod - 1) / t, mod) == 1) {
return 0;
}
}
return 1;
}
void solve() {
scanf("%d%d%d%d%d%d", &n, &K, &L, &X, &Y, &mod);
--X;
--Y;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
scanf("%d", &a.a[i][j]);
}
}
int g = -1;
for (int i = 2;; ++i) {
if (check(i)) {
g = i;
break;
}
}
int w = qpow(g, (mod - 1) / K, mod);
int iw = qpow(w, mod - 2, mod);
vector<int> b(K);
for (int i = 0; i < K; ++i) {
int wi = qpow(w, i, mod);
mat t = a;
for (int j = 0; j < n; ++j) {
for (int k = 0; k < n; ++k) {
t.a[j][k] = 1LL * t.a[j][k] * wi % mod;
}
}
for (int j = 0; j < n; ++j) {
t.a[j][j] = (t.a[j][j] + 1) % mod;
}
t = qpow(t, L);
b[i] = t.a[X][Y];
}
vector<int> res = bls(K - 1, K - 1, iw, b);
int inv = qpow(K, mod - 2, mod);
for (int i = 0; i < K; ++i) {
printf("%lld\n", 1LL * res[i] * inv % mod);
}
}
int main() {
int T = 1;
// scanf("%d", &T);
while (T--) {
solve();
}
return 0;
}