-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10830.cpp
69 lines (66 loc) · 1.33 KB
/
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
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
#include <iostream>
using namespace std;
int n;
struct mtrx {
int arr[5][5];
};
struct mtrx a;
struct mtrx func(unsigned long long int p) {
if (p == 1) {
struct mtrx returnmtrx = a;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
returnmtrx.arr[i][j] = a.arr[i][j];
}
}
return returnmtrx;
}
else {
struct mtrx tempmtrx = func(p / 2);
struct mtrx returnmtrx;
struct mtrx rreturnmtrxx;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
int returnnum = 0;
for (int k = 0; k < n; k++) {
returnnum += tempmtrx.arr[i][k] * tempmtrx.arr[k][j];
}
returnmtrx.arr[i][j] = returnnum % 1000;
}
}
if (p % 2 == 0) {
return returnmtrx;
}
else {
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
int returnnum = 0;
for (int k = 0; k < n; k++) {
returnnum += returnmtrx.arr[i][k] * a.arr[k][j];
}
rreturnmtrxx.arr[i][j] = returnnum % 1000;
}
}
return rreturnmtrxx;
}
}
}
int main(void) {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
unsigned long long int b;
cin >> n >> b;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> a.arr[i][j];
}
}
a = func(b);
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cout << a.arr[i][j] % 1000 << " ";
}
cout << "\n";
}
}