-
Notifications
You must be signed in to change notification settings - Fork 0
/
10830.cpp
67 lines (61 loc) · 1.39 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
#include<iostream>
#include<vector>
using namespace std;
long long n, b;
long long v[6][6] = {0, };
long long answer[6][6];
long long one[6][6];
void X(long long target);
void square(long long a[6][6], long long b[6][6]);
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> b;
long long tmp;
for(int i = 0; i < n; i ++){
for(int j = 0; j < n; j++){
cin >> tmp;
v[i][j]=answer[i][j] = tmp;
}
}
for (int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
one[i][j] = 1;
}
}
X(b);
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
cout << answer[i][j]%1000 << ' ';
}
cout << '\n';
}
}
void X(long long target){
if(target==1)return;
if(target%2 == 1){
X(target-1);
square(answer, v);
}
else{
X(target/2);
square(answer, answer);
}
}
void square(long long a[6][6], long long b[6][6]){
long long answerTmp[6][6] = {0, };
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
for(int k = 0; k < n; k++){
answerTmp[i][j] += ((a[i][k]%1000)*(b[k][j]%1000))%1000;
}
}
}
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
answer[i][j] = (answerTmp[i][j])%1000;
}
}
return;
}