-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path7677.cpp
More file actions
63 lines (51 loc) · 1.12 KB
/
7677.cpp
File metadata and controls
63 lines (51 loc) · 1.12 KB
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
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
long long n=0;
int ans =0;
class matrix{
public:
int a,b,c,d;
matrix(int _a,int _b,int _c,int _d){
a=_a; b=_b;c=_c;d=_d;
}
};
matrix multiply(matrix m1, matrix m2){
// cout << "qq";
matrix ret = matrix((m1.a*m2.a+m1.b*m2.c)%10000, (m1.a*m2.b+m1.b*m2.d)%10000,
(m1.c*m2.a+m1.d*m2.c)%10000, (m1.c*m2.b+m1.d*m2.d)%10000);
return ret;
}
matrix solve(long long k){
// cout << k;
matrix e = matrix(1,1,1,0);
if(k==1){
return e;
} else{
matrix m = solve(k/2);
if(k%2==0){
matrix a = multiply(m,m);
return a;
}else{
matrix a = multiply(multiply(m,m),e);
return a;
}
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
while(n != -1){
cin >> n;
if(n==-1) break;
if(n==0){
cout << 0 << '\n';
continue;
}else {
matrix a = solve(n);
cout << a.c << "\n";
}
}
}