From 8d6c13ae1947d7cb69043cbad14debecf626cac2 Mon Sep 17 00:00:00 2001 From: hanyixuanten <105723997+hanyixuanten@users.noreply.github.com> Date: Sun, 6 Sep 2026 14:49:21 +0800 Subject: [PATCH] new file: P3390.cpp --- P3390.cpp | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 P3390.cpp diff --git a/P3390.cpp b/P3390.cpp new file mode 100644 index 0000000..48d1d5c --- /dev/null +++ b/P3390.cpp @@ -0,0 +1,75 @@ +#include +const int mod = 1e9 + 7; +#define int long long +using namespace std; +int n; +struct node +{ + int a[105][105]; + void operator*=(const node &b) + { + int res[105][105] = {}; + for (int i = 1; i <= n; ++i) + { + for (int j = 1; j <= n; ++j) + { + for (int k = 1; k <= n; ++k) + { + res[i][j] += (a[i][k] * b.a[k][j]) % mod; + res[i][j] %= mod; + } + } + } + for (int i = 1; i <= n; ++i) + { + for (int j = 1; j <= n; ++j) + { + a[i][j] = res[i][j] % mod; + } + } + } +} a; +long long k; +node pow(node a, int k) +{ + node res; + for (int i = 1; i <= n; ++i) + for (int j = 1; j <= n; ++j) + res.a[i][j] = (i == j); + while (k) + { + if (k & 1) + res *= a; + a *= a; + k >>= 1; + } + while (k) + { + if (k & 1) + res *= a; + a *= a; + k >>= 1; + } + return res; +} +signed main() +{ + scanf("%lld%lld", &n, &k); + for (int i = 1; i <= n; ++i) + { + for (int j = 1; j <= n; ++j) + { + scanf("%lld", &a.a[i][j]); + } + } + node res = pow(a, k); + for (int i = 1; i <= n; ++i) + { + for (int j = 1; j <= n; ++j) + { + printf("%lld ", res.a[i][j]); + } + puts(""); + } + return 0; +} \ No newline at end of file