-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10830.cpp
44 lines (38 loc) · 798 Bytes
/
10830.cpp
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
#include <iostream>
#include <queue>
using namespace std;
long long n, b;
long long x[5][5], tmp[5][5], ans[5][5];
void multi(long long a[5][5], long long b[5][5]) {
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) {
tmp[i][j] = 0;
for (int k = 0; k < n; k++)
tmp[i][j] += a[i][k] * b[k][j];
tmp[i][j] %= 1000;
}
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
a[i][j] = tmp[i][j];
}
int main() {
cin.tie(0);
std::ios_base::sync_with_stdio(0);
cin >> n >> b;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++)
cin >> x[i][j];
ans[i][i] = 1;
}
while (b > 0) {
if (b % 2 == 1)
multi(ans, x);
multi(x, x);
b /= 2;
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++)
cout << ans[i][j] << " ";
cout << "\n";
}
}