-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathB11444.java
More file actions
56 lines (42 loc) · 1.21 KB
/
B11444.java
File metadata and controls
56 lines (42 loc) · 1.21 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
package Practice;
public class B11444 { //ÇǺ¸³ªÄ¡ ¼ö 6
static final int MOD = 1000000007;
static long[][] X = {{1, 1}, {1, 0}};
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
long[][] A = {{1, 1}, {1, 0}};
long N = read();
if(N == 1) System.out.println(1);
else System.out.println(pow(A, N - 1)[0][0]);
}
static long[][] pow(long[][] A, long exp) {
if(exp == 1) return A;
A = pow(A, exp / 2);
A = mul(A, A);
if(exp % 2 == 1) A = mul(A, X);
return A;
}
static long[][] mul(long[][] o1, long[][] o2) {
long[][] res = new long[2][2];
res[0][0] = (o1[0][0] * o2[0][0] + o1[0][1] * o2[1][0]) % MOD;
res[0][1] = (o1[0][0] * o2[0][1] + o1[0][1] * o2[1][1]) % MOD;
res[1][0] = (o1[1][0] * o2[0][0] + o1[1][1] * o2[1][0]) % MOD;
res[1][1] = (o1[1][0] * o2[0][1] + o1[1][1] * o2[1][1]) % MOD;
return res;
}
static long read() throws Exception {
long n = System.in.read();
int c;
boolean minus = false;
if(n == 45) {
minus = true;
n = System.in.read();
}
else if(n == 10) n = System.in.read();
n &= 15;
while((c = System.in.read()) >= 48) {
n = (n << 3) + (n << 1) + (c & 15);
}
return n;
}
}